private void AddFullPackage(string fullBoxWeight, int valuePerFullBox, inv_detl details, string packagingTypeCode, string currencyCode, UPSRateService.PackageType[] pkgArray, int pos) { var package = new UPSRateService.PackageType(); var packageWeight = new UPSRateService.PackageWeightType(); packageWeight.Weight = fullBoxWeight; var uom = new UPSRateService.CodeDescriptionType(); uom.Code = "LBS"; uom.Description = "pounds"; packageWeight.UnitOfMeasurement = uom; package.PackageWeight = packageWeight; var packageDimensions = new UPSRateService.DimensionsType(); packageDimensions.Height = ((int)details.CASE_HI.Value).ToString(); packageDimensions.Length = ((int)details.CASE_LEN.Value).ToString(); packageDimensions.Width = ((int)details.CASE_WT.Value).ToString(); var packDimType = new UPSRateService.CodeDescriptionType(); packDimType.Code = "IN"; packDimType.Description = "Inches"; packageDimensions.UnitOfMeasurement = packDimType; package.Dimensions = packageDimensions; var packageServiceOptions = new UPSRateService.PackageServiceOptionsType(); var insuredValue = new UPSRateService.InsuredValueType(); insuredValue.CurrencyCode = currencyCode; insuredValue.MonetaryValue = valuePerFullBox.ToString(); packageServiceOptions.DeclaredValue = insuredValue; package.PackageServiceOptions = packageServiceOptions; var packType = new UPSRateService.CodeDescriptionType(); packType.Code = packagingTypeCode; package.PackagingType = packType; pkgArray[pos] = package; }
public RateResponse CallUPSRateRequest(string serviceCode, int Qty, int nrBoxes, int itemsInLastBox, string fullBoxWeight, int valuePerFullBox, int valuePerPartialBox, string partialBoxWeight, inv_detl details, string packagingTypeCode, string currencyCode, decimal unitPrice, bool isResidentialAddress)//, out string requestXML) { var upsService = new RateService(); var rateResponse = new RateResponse(); var rateRequest = new RateRequest(); AddCustomerClassification(rateRequest); AddUpsSecurity(upsService); var request = new RequestType(); String[] requestOption = { "Rate" }; request.RequestOption = requestOption; //this can be Rate or Shop rateRequest.Request = request; var shipment = new UPSRateService.ShipmentType(); AddShipper(shipment); AddShipFromAddress(shipment); AddShipToAddress(shipment, isResidentialAddress); var service = new CodeDescriptionType(); service.Code = serviceCode; shipment.Service = service; var optype = new UPSRateService.ShipmentRatingOptionsType(); optype.NegotiatedRatesIndicator = string.Empty; shipment.ShipmentRatingOptions = optype; AddPackageArray(nrBoxes, itemsInLastBox, fullBoxWeight, partialBoxWeight, valuePerFullBox, valuePerPartialBox, details, packagingTypeCode, currencyCode, shipment); AddInvoiceTotalType(Qty, unitPrice, shipment); rateRequest.Shipment = shipment; //var serializer = new XmlSerializer(typeof(RateRequest)); //using (var writer = new StringWriter()) //{ // serializer.Serialize(writer, rateRequest); // requestXML = writer.ToString(); //} rateResponse = upsService.ProcessRate(rateRequest); return(rateResponse); }
private void AddPackageArray(int nrBoxes, int itemsInLastBox, string fullBoxWeight, string partialBoxWeight, int valuePerFullBox, int valuePerPartialBox, inv_detl details, string packagingTypeCode, string currencyCode, UPSRateService.ShipmentType shipment) { UPSRateService.PackageType[] pkgArray; //if (itemsInLastBox > 0) // pkgArray = new UPSRateService.PackageType[nrBoxes]; //else pkgArray = new UPSRateService.PackageType[nrBoxes]; int tempItemCount = nrBoxes; if (itemsInLastBox > 0) { tempItemCount = tempItemCount - 1; } for (int i = 0; i < tempItemCount; i++) { AddFullPackage(fullBoxWeight, valuePerFullBox, details, packagingTypeCode, currencyCode, pkgArray, i); } if (itemsInLastBox > 0 && !string.IsNullOrEmpty(partialBoxWeight)) { AddPartialPackage(nrBoxes, partialBoxWeight, valuePerPartialBox, details, packagingTypeCode, currencyCode, pkgArray); } shipment.Package = pkgArray; }
private void AddPartialPackage(int nrBoxes, string partialBoxWeight, int valuePerPartialBox, inv_detl details, string packagingTypeCode, string currencyCode, UPSRateService.PackageType[] pkgArray) { var package = new UPSRateService.PackageType(); var packageWeight = new UPSRateService.PackageWeightType(); packageWeight.Weight = partialBoxWeight; var uom = new UPSRateService.CodeDescriptionType(); uom.Code = "LBS"; uom.Description = "pounds"; packageWeight.UnitOfMeasurement = uom; package.PackageWeight = packageWeight; var packageDimensions = new UPSRateService.DimensionsType(); //packageDimensions.Height = ((int)details.CASE_HI.Value).ToString(); //packageDimensions.Length = ((int)details.CASE_LEN.Value).ToString(); //packageDimensions.Width = ((int)details.CASE_WT.Value).ToString(); packageDimensions.Height = "0"; packageDimensions.Length = "0"; packageDimensions.Width = "0"; var packDimType = new UPSRateService.CodeDescriptionType(); packDimType.Code = "IN"; packDimType.Description = "Inches"; packageDimensions.UnitOfMeasurement = packDimType; package.Dimensions = packageDimensions; var packageServiceOptions = new UPSRateService.PackageServiceOptionsType(); var insuredValue = new UPSRateService.InsuredValueType(); insuredValue.CurrencyCode = currencyCode; insuredValue.MonetaryValue = valuePerPartialBox.ToString(); packageServiceOptions.DeclaredValue = insuredValue; package.PackageServiceOptions = packageServiceOptions; var packType = new UPSRateService.CodeDescriptionType(); packType.Code = packagingTypeCode; package.PackagingType = packType; pkgArray[nrBoxes - 1] = package; }
private void AddPackageArray(int nrBoxes, int itemsInLastBox, string fullBoxWeight, string partialBoxWeight, int valuePerFullBox, int valuePerPartialBox, inv_detl details, string packagingTypeCode, string currencyCode, UPSRateService.ShipmentType shipment) { UPSRateService.PackageType[] pkgArray; //if (itemsInLastBox > 0) // pkgArray = new UPSRateService.PackageType[nrBoxes]; //else pkgArray = new UPSRateService.PackageType[nrBoxes]; int tempItemCount = nrBoxes; if (itemsInLastBox > 0) tempItemCount = tempItemCount - 1; for (int i = 0; i < tempItemCount; i++) { AddFullPackage(fullBoxWeight, valuePerFullBox, details, packagingTypeCode, currencyCode, pkgArray, i); } if (itemsInLastBox > 0 && !string.IsNullOrEmpty(partialBoxWeight)) AddPartialPackage(nrBoxes, partialBoxWeight, valuePerPartialBox, details, packagingTypeCode, currencyCode, pkgArray); shipment.Package = pkgArray; }
//, out string requestXML) public RateResponse CallUPSRateRequest(string serviceCode, int Qty, int nrBoxes, int itemsInLastBox, string fullBoxWeight, int valuePerFullBox, int valuePerPartialBox, string partialBoxWeight, inv_detl details, string packagingTypeCode, string currencyCode, decimal unitPrice, bool isResidentialAddress) { var upsService = new RateService(); var rateResponse = new RateResponse(); var rateRequest = new RateRequest(); AddCustomerClassification(rateRequest); AddUpsSecurity(upsService); var request = new RequestType(); String[] requestOption = { "Rate" }; request.RequestOption = requestOption; //this can be Rate or Shop rateRequest.Request = request; var shipment = new UPSRateService.ShipmentType(); AddShipper(shipment); AddShipFromAddress(shipment); AddShipToAddress(shipment, isResidentialAddress); var service = new CodeDescriptionType(); service.Code = serviceCode; shipment.Service = service; var optype = new UPSRateService.ShipmentRatingOptionsType(); optype.NegotiatedRatesIndicator = string.Empty; shipment.ShipmentRatingOptions = optype; AddPackageArray(nrBoxes, itemsInLastBox, fullBoxWeight, partialBoxWeight, valuePerFullBox, valuePerPartialBox, details, packagingTypeCode, currencyCode, shipment); AddInvoiceTotalType(Qty, unitPrice, shipment); rateRequest.Shipment = shipment; //var serializer = new XmlSerializer(typeof(RateRequest)); //using (var writer = new StringWriter()) //{ // serializer.Serialize(writer, rateRequest); // requestXML = writer.ToString(); //} rateResponse = upsService.ProcessRate(rateRequest); return rateResponse; }
private void AddPartialPackage(int nrBoxes, string partialBoxWeight, int valuePerPartialBox, inv_detl details, string packagingTypeCode, string currencyCode, UPSRateService.PackageType[] pkgArray) { var package = new UPSRateService.PackageType(); var packageWeight = new UPSRateService.PackageWeightType(); packageWeight.Weight = partialBoxWeight; var uom = new UPSRateService.CodeDescriptionType(); uom.Code = "LBS"; uom.Description = "pounds"; packageWeight.UnitOfMeasurement = uom; package.PackageWeight = packageWeight; var packageDimensions = new UPSRateService.DimensionsType(); packageDimensions.Height = "0"; packageDimensions.Length = "0"; packageDimensions.Width = "0"; var packDimType = new UPSRateService.CodeDescriptionType(); packDimType.Code = "IN"; packDimType.Description = "Inches"; packageDimensions.UnitOfMeasurement = packDimType; package.Dimensions = packageDimensions; var packageServiceOptions = new UPSRateService.PackageServiceOptionsType(); var insuredValue = new UPSRateService.InsuredValueType(); insuredValue.CurrencyCode = currencyCode; insuredValue.MonetaryValue = valuePerPartialBox.ToString(); packageServiceOptions.DeclaredValue = insuredValue; package.PackageServiceOptions = packageServiceOptions; var packType = new UPSRateService.CodeDescriptionType(); packType.Code = packagingTypeCode; package.PackagingType = packType; pkgArray[nrBoxes - 1] = package; }