如何从UPS Rate API获得费率?

时间:2015-06-27 12:43:53

标签: api nopcommerce ups

我正在使用nopcommerce 3.5。我添加了TransitInTime和Rate API的插件。我想通过拨打UPS Rate API获得费率。我希望页面加载时下拉列表中的所有费率。

因此,对于第一个使用RateWebReference的web服务的测试应用程序,我只得到一个Rate但我想要所有送货选项的费率。

这是我的RateWSClient.cs代码

  RateService rate = new RateService();
                RateRequest rateRequest = new RateRequest();
                UPSSecurity upss = new UPSSecurity();
                UPSSecurityServiceAccessToken upssSvcAccessToken = new UPSSecurityServiceAccessToken();
                upssSvcAccessToken.AccessLicenseNumber = "CC....";
                upss.ServiceAccessToken = upssSvcAccessToken;
                UPSSecurityUsernameToken upssUsrNameToken = new UPSSecurityUsernameToken();
                upssUsrNameToken.Username = "gi..";
                upssUsrNameToken.Password = "Ch..";
                upss.UsernameToken = upssUsrNameToken;
                rate.UPSSecurityValue = upss;
                RequestType request = new RequestType();
                String[] requestOption = { "Rate" };
                request.RequestOption = requestOption;

                rateRequest.Request = request;
                ShipmentType shipment = new ShipmentType();
                ShipperType shipper = new ShipperType();

                shipper.ShipperNumber = "A65V88";
                RateWSSample.RateWebReference1.AddressType shipperAddress = new RateWSSample.RateWebReference1.AddressType();
                String[] addressLine = { "", "", "" };
                shipperAddress.AddressLine = addressLine;
                shipperAddress.City = "";
                shipperAddress.PostalCode = "30076";
                shipperAddress.StateProvinceCode = "GA";
                shipperAddress.CountryCode = "US";
                shipperAddress.AddressLine = addressLine;
                shipper.Address = shipperAddress;
                shipment.Shipper = shipper;
                ShipFromType shipFrom = new ShipFromType();
                RateWSSample.RateWebReference1.AddressType shipFromAddress = new RateWSSample.RateWebReference1.AddressType();
                shipFromAddress.AddressLine = addressLine;
                shipFromAddress.City = "";
                shipFromAddress.PostalCode = "30076";
                shipFromAddress.StateProvinceCode = "GA";
                shipFromAddress.CountryCode = "US";
                shipFrom.Address = shipFromAddress;
                shipment.ShipFrom = shipFrom;
                ShipToType shipTo = new ShipToType();
                ShipToAddressType shipToAddress = new ShipToAddressType();
                String[] addressLine1 = { "", "", "" };
                shipToAddress.AddressLine = addressLine1;
                shipToAddress.City = "";
                shipToAddress.PostalCode = "92262";
                shipToAddress.StateProvinceCode = "";
                shipToAddress.CountryCode = "US";
                shipTo.Address = shipToAddress;
                shipment.ShipTo = shipTo;
                CodeDescriptionType service = new CodeDescriptionType();

                //Below code uses dummy date for reference. Please udpate as required.
                service.Code = "02";
                shipment.Service = service;
                PackageType package = new PackageType();
                PackageWeightType packageWeight = new PackageWeightType();
                packageWeight.Weight = "125";
                CodeDescriptionType uom = new CodeDescriptionType();
                uom.Code = "LBS";
                uom.Description = "pounds";
                packageWeight.UnitOfMeasurement = uom;
                package.PackageWeight = packageWeight;
                CodeDescriptionType packType = new CodeDescriptionType();
                packType.Code = "02";
                package.PackagingType = packType;
                PackageType[] pkgArray = { package };
                shipment.Package = pkgArray;

               //Shipping Rate Chart

               // ShipmentRatingOptionsType SRO = new ShipmentRatingOptionsType();
                //SRO.RateChartIndicator = "";
                //shipment.ShipmentRatingOptions= SRO;

                //rateRequest.Shipment = shipment;


                ShipmentRatingOptionsType SRO = new ShipmentRatingOptionsType();
                SRO.NegotiatedRatesIndicator = "";
                shipment.ShipmentRatingOptions = SRO;

                rateRequest.Shipment = shipment;

                System.Net.ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy();
                Console.WriteLine(rateRequest);
                RateResponse rateResponse = rate.ProcessRate(rateRequest);
                Console.WriteLine("The transaction was a " + rateResponse.Response.ResponseStatus.Description);
                Console.WriteLine("Total Shipment Charges " + rateResponse.RatedShipment[0].TotalCharges.MonetaryValue + rateResponse.RatedShipment[0].TotalCharges.CurrencyCode);
                Console.ReadKey();

1 个答案:

答案 0 :(得分:2)

我已经解决了这个问题。所以如果你遇到这种问题,别忘了使用

String[] requestOption = { "Shop" };

取代

String[] requestOption = { "Rate" };

然后您将获得所有送货方式的费率。