Tom Rundo
Tom Rundo

Reputation: 27

UPS Rating API C# .Net

I am trying to get the UPS Rating API that now supports Time In Transit to work. I have the latest WSDL (UPS API). I keep getting an exception error "An exception has been raised as a result of client data." and I can not figure out what is the problem. Note: The "Rate" requestOption works with no issues - when TimeinTransit and DeliveryInformation data is commented out.

What could be wrong? Any help would be appreciated, thank you.

Here is my C# code:

UPSRateWS.RequestType request = new UPSRateWS.RequestType();
String[] requestOption = { "ratetimeintransit" };
request.RequestOption = requestOption;
request.SubVersion = "1601";

rateRequest.Request = request;

UPSRateWS.ShipmentType shipment = new UPSRateWS.ShipmentType();
UPSRateWS.ShipperType shipper = new UPSRateWS.ShipperType();

UPSRateWS.ShipmentRatingOptionsType shipmentRatingOptions = new 
     UPSRateWS.ShipmentRatingOptionsType();
shipmentRatingOptions.NegotiatedRatesIndicator = "";
shipmentRatingOptions.RateChartIndicator = "";

shipment.ShipmentRatingOptions = shipmentRatingOptions;

UPSRateWS.TimeInTransitRequestType timeInTransit = new 
     UPSRateWS.TimeInTransitRequestType();
UPSRateWS.PickupType pickupInTransitType = new UPSRateWS.PickupType();

pickupInTransitType.Date = "20170414";
pickupInTransitType.Time = "1630";

timeInTransit.Pickup = pickupInTransitType;
timeInTransit.PackageBillType = "02";

shipment.NumOfPieces = "1";

shipment.DeliveryTimeInformation = timeInTransit;

UPSRateWS.ShipmentWeightType shipWeightType = new 
     UPSRateWS.ShipmentWeightType();
shipWeightType.Weight = "10.80";

UPSRateWS.CodeDescriptionType shipWeightUOM = new 
     UPSRateWS.CodeDescriptionType();
shipWeightUOM.Code = "LBS";
shipWeightUOM.Description = "pounds";
shipWeightType.UnitOfMeasurement = shipWeightUOM;
shipment.ShipmentTotalWeight = shipWeightType;

shipper.ShipperNumber = "XXXXXX";

UPSRateWS.AddressType shipperAddress = new UPSRateWS.AddressType();
string testAddr = "7650 Tyler Blvd";
String[] addressLine = { testAddr };
shipperAddress.AddressLine = addressLine;
shipperAddress.City = "Mentor";
shipperAddress.PostalCode = "44060";
shipperAddress.StateProvinceCode = "OH";
shipperAddress.CountryCode = "US";
shipperAddress.AddressLine = addressLine;
shipper.Address = shipperAddress;

shipment.Shipper = shipper;

UPSRateWS.ShipFromType shipFrom = new UPSRateWS.ShipFromType();
UPSRateWS.ShipAddressType shipFromAddress = new UPSRateWS.ShipAddressType();

string testAddr2 = "";
String[] addressLine1 = { testAddr2 };
shipFromAddress.AddressLine = addressLine1;
shipFromAddress.City = "";
shipFromAddress.PostalCode = "45069";
shipFromAddress.StateProvinceCode = "OH";
shipFromAddress.CountryCode = "US";
shipFrom.Address = shipFromAddress;

shipment.ShipFrom = shipFrom;

UPSRateWS.ShipToType shipTo = new UPSRateWS.ShipToType();
UPSRateWS.ShipToAddressType shipToAddress = new UPSRateWS.ShipToAddressType();

string testAddr3 = "7650 Tyler Blvd";
String[] addressLine2 = { testAddr3 };
shipToAddress.AddressLine = addressLine2;
shipToAddress.City = "Mentor";
shipToAddress.PostalCode = "44060";
shipToAddress.StateProvinceCode = "OH";
shipToAddress.CountryCode = "US";
shipToAddress.ResidentialAddressIndicator = "1";
shipTo.Address = shipToAddress;

shipment.ShipTo = shipTo;

UPSRateWS.CodeDescriptionType service = new UPSRateWS.CodeDescriptionType();
service.Code = "03";    
shipment.Service = service;

UPSRateWS.PackageType package = new UPSRateWS.PackageType();
UPSRateWS.PackageWeightType packageWeight = new UPSRateWS.PackageWeightType();
packageWeight.Weight = "10.80";

UPSRateWS.CodeDescriptionType uom = new UPSRateWS.CodeDescriptionType();
uom.Code = "LBS";
uom.Description = "pounds";
packageWeight.UnitOfMeasurement = uom;
package.PackageWeight = packageWeight;

UPSRateWS.CodeDescriptionType packType = new UPSRateWS.CodeDescriptionType();
packType.Code = "02";
package.PackagingType = packType;

UPSRateWS.PackageServiceOptionsType packServType = new 
     UPSRateWS.PackageServiceOptionsType();
UPSRateWS.InsuredValueType insuredValueType = new UPSRateWS.InsuredValueType();
insuredValueType.CurrencyCode = "USD";
insuredValueType.MonetaryValue = "65.75";
packServType.DeclaredValue = insuredValueType;

UPSRateWS.ShipperDeclaredValueType shipperDeclaredValueType = new 
     UPSRateWS.ShipperDeclaredValueType();
shipperDeclaredValueType.CurrencyCode = "USD";
shipperDeclaredValueType.MonetaryValue = "65.75";
packServType.ShipperDeclaredValue = shipperDeclaredValueType;
package.PackageServiceOptions = packServType;

UPSRateWS.PackageType[] pkgArray = { package };
shipment.Package = pkgArray;
rateRequest.Shipment = shipment;

UPSRateWS.CodeDescriptionType pickupType = new UPSRateWS.CodeDescriptionType();
pickupType.Code = "01";
pickupType.Description = "Daily Pickup";
rateRequest.PickupType = pickupType;

UPSRateWS.RateResponse rateResponse = myRatePortTypeClient.ProcessRate(upss, 
     rateRequest);

Upvotes: 1

Views: 2307

Answers (1)

Ike Rolfe
Ike Rolfe

Reputation: 43

You need to include both the "rate" option and the "ratetimeintransit" options:

String[] requestOption = { "rate","ratetimeintransit" };

Upvotes: 0

Related Questions