Home
Products
Forums
Help
Publish Article
Go Freelance

Integrate USPS Shipping Calculations in ASP.Net Shopping Cart

Downloads

If you are seeing this section and do not see download links, this means that you are not logged into our site. If you already are a member, click on the login link and login into site and come back to this page for downloading the control files. If you are not a member, click on registration link to become a Winista member and download the control for free.

Sorted gird with image

If you are developing Shopping cart for your ASP.Net web application or any application that requires you to calculate shipping charges on the fly using the shipping carrier's web service then you definitely want to try our ShippingCalc.Net library. This sample demonstrates a very simple use of the library to show you how you can calculate shipping charges for USPS carrier.

Sub TestDomesticRateCalculator()
        Dim obGateway As WSGateway = 
            New WSGateway(CarrierType.USPS, "your unique id", String.Empty, "http://production.shippingapis.com/ShippingAPI.dll", False)
        Dim rateTxn As RateCalculationTransaction = obGateway.CreateDomesticRateCalculationTransaction()
        Dim obPackage As DomesticPackage = rateTxn.CreateNewDomesticPackage()
        obPackage.PackageID = "1"
        obPackage.OriginZip = "03033"
        obPackage.DestinationZip = "03063"
        obPackage.WeightInPound = 10
        obPackage.WeightInOunce = 5
        obPackage.PackageSizeType = PackageSizeType.Large
        obPackage.ContainerType = ContainerType.FlatRateBox
        obPackage.DeliveryServiceType = DeliveryServiceType.All
        obPackage.Machinable = True
        rateTxn.Packages.Add(obPackage)

        Dim obResp As GatewayResponse = obGateway.SubmitRateCalculationTransaction(rateTxn)
        If (obResp.StatusCode <> 0) Then
            Console.WriteLine("Gateway Error")
            If Not (obResp.GatewayError Is Nothing) Then
                Console.WriteLine(obResp.GatewayError.ErrorDescription)
                Return
            End If
        End If

        Console.WriteLine("Gateway Response")
        Dim obRespPackage As DomesticPackage
        For Each obRespPackage In rateTxn.Packages
            Console.WriteLine("***********START**************")
            Console.WriteLine("Package ID: {0}", obRespPackage.PackageID)
            Console.WriteLine(" Zone: {0}", obRespPackage.Zone)
            If Not (obRespPackage.PostageCollection Is Nothing) Then
                Dim obPostage As USPSDomesticPostage
                For Each obPostage In obRespPackage.PostageCollection
                    Console.WriteLine("\tService Type: {0} - Rate:{1}", obPostage.MailService, obPostage.MailRate)
                    Console.WriteLine("")
                Next obPostage
            End If
            Console.WriteLine("***********END****************")
            Console.WriteLine("")
        Next obRespPackage
    End Sub
							
Go Freelance
Home     About us     Contact us    Copyright    Privacy Policy    Return Policy    Advertisers
Copyright © Netomatix