private void AddFullPackage(string fullBoxWeight, int valuePerFullBox, inv_detl details, PackageType[] pkgArray, int pos) { PackageType package = new PackageType(); PackageWeightType packageWeight = new PackageWeightType(); packageWeight.Weight = fullBoxWeight; UPS_Shipping_Rate.UPSRateService.CodeDescriptionType uom = new UPS_Shipping_Rate.UPSRateService.CodeDescriptionType(); uom.Code = "LBS"; uom.Description = "pounds"; packageWeight.UnitOfMeasurement = uom; package.PackageWeight = packageWeight; DimensionsType packageDimensions = new 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(); UPS_Shipping_Rate.UPSRateService.CodeDescriptionType packDimType = new UPS_Shipping_Rate.UPSRateService.CodeDescriptionType(); packDimType.Code = "IN"; packDimType.Description = "Inches"; packageDimensions.UnitOfMeasurement = packDimType; package.Dimensions = packageDimensions; PackageServiceOptionsType packageServiceOptions = new PackageServiceOptionsType(); InsuredValueType insuredValue = new InsuredValueType(); insuredValue.CurrencyCode = "USD"; insuredValue.MonetaryValue = valuePerFullBox.ToString(); packageServiceOptions.DeclaredValue = insuredValue; package.PackageServiceOptions = packageServiceOptions; UPS_Shipping_Rate.UPSRateService.CodeDescriptionType packType = new UPS_Shipping_Rate.UPSRateService.CodeDescriptionType(); packType.Code = "02"; package.PackagingType = packType; pkgArray[pos] = package; }
private void GetRateFromUPS(int Qty, int nrBoxes, int itemsInLastBox, string fullBoxWeight, int valuePerFullBox, int valuePerPartialBox, string partialBoxWeight, inv_detl details, decimal unitPrice) { try { List<Result> lst = new List<Result>(); lst.Add(new Result() { service = "UPS Next Day Air®", code = "01" }); lst.Add(new Result() { service = "UPS Second Day Air®", code = "02" }); lst.Add(new Result() { service = "UPS Ground", code = "03" }); lst.Add(new Result() { service = "UPS Express", code = "07" }); lst.Add(new Result() { service = "UPS ExpeditedSM", code = "08" }); lst.Add(new Result() { service = "UPS Standard", code = "11" }); lst.Add(new Result() { service = "UPS Three-Day Select®", code = "12" }); lst.Add(new Result() { service = "UPS Next Day Air Saver®", code = "13" }); lst.Add(new Result() { service = "UPS Next Day Air® Early A.M. SM", code = "14" }); foreach (Result r in lst) { RateService upsService = new RateService(); try { RateResponse rateResponse = CallUPSRateRequest(r.code, Qty, nrBoxes, itemsInLastBox, fullBoxWeight, valuePerFullBox, valuePerPartialBox, partialBoxWeight, details, unitPrice, upsService); if (rateResponse.RatedShipment != null) { foreach (var rshipment in rateResponse.RatedShipment) { r.cost = rshipment.NegotiatedRateCharges.TotalCharge.MonetaryValue + " " + rshipment.NegotiatedRateCharges.TotalCharge.CurrencyCode; if (rshipment.GuaranteedDelivery != null && rshipment.GuaranteedDelivery.BusinessDaysInTransit != null) r.time = rshipment.GuaranteedDelivery.BusinessDaysInTransit + " days"; } } } catch (System.Web.Services.Protocols.SoapException ex) { } } //lstView.DataSource = lst; //lstView.DataBind(); //Display the response data ViewBag.ResultList = lst; } catch (System.Web.Services.Protocols.SoapException ex) { } }
private RateResponse CallUPSRateRequest(string scode, int Qty, int nrBoxes, int itemsInLastBox, string fullBoxWeight, int valuePerFullBox, int valuePerPartialBox, string partialBoxWeight, inv_detl details, decimal unitPrice, RateService upsService) { RateResponse rateResponse = new RateResponse(); try { RateRequest rateRequest = new RateRequest(); AddCustomerClassification(rateRequest); AddUpsSecurity(upsService); UPS_Shipping_Rate.UPSRateService.RequestType request = new RequestType(); String[] requestOption = { "Rate" }; request.RequestOption = requestOption; rateRequest.Request = request; ShipmentType shipment = new ShipmentType(); AddShipper(shipment); AddShipFromAddress(shipment); AddShipToAddress(shipment); UPS_Shipping_Rate.UPSRateService.CodeDescriptionType service = new UPS_Shipping_Rate.UPSRateService.CodeDescriptionType(); service.Code = scode.ToString(); shipment.Service = service; ShipmentRatingOptionsType optype = new ShipmentRatingOptionsType(); optype.NegotiatedRatesIndicator = string.Empty; shipment.ShipmentRatingOptions = optype; AddPackageArray(nrBoxes, itemsInLastBox, fullBoxWeight, partialBoxWeight, valuePerFullBox, valuePerPartialBox, details, shipment); AddInvoiceTotalType(Qty, unitPrice, shipment); rateRequest.Shipment = shipment; // ServicePointManager.ServerCertificateValidationCallback = ValidateRemoteCertificate; rateResponse = upsService.ProcessRate(rateRequest); } catch (Exception ex) { } return rateResponse; }
private void AddPartialPackage(int nrBoxes, string partialBoxWeight, int valuePerPartialBox, inv_detl details, PackageType[] pkgArray) { PackageType package = new PackageType(); PackageWeightType packageWeight = new PackageWeightType(); packageWeight.Weight = partialBoxWeight; UPS_Shipping_Rate.UPSRateService.CodeDescriptionType uom = new UPS_Shipping_Rate.UPSRateService.CodeDescriptionType(); uom.Code = "LBS"; uom.Description = "pounds"; packageWeight.UnitOfMeasurement = uom; package.PackageWeight = packageWeight; DimensionsType packageDimensions = new 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(); UPS_Shipping_Rate.UPSRateService.CodeDescriptionType packDimType = new UPS_Shipping_Rate.UPSRateService.CodeDescriptionType(); packDimType.Code = "IN"; packDimType.Description = "Inches"; packageDimensions.UnitOfMeasurement = packDimType; package.Dimensions = packageDimensions; PackageServiceOptionsType packageServiceOptions = new PackageServiceOptionsType(); InsuredValueType insuredValue = new InsuredValueType(); insuredValue.CurrencyCode = "USD"; insuredValue.MonetaryValue = valuePerPartialBox.ToString(); packageServiceOptions.DeclaredValue = insuredValue; package.PackageServiceOptions = packageServiceOptions; UPS_Shipping_Rate.UPSRateService.CodeDescriptionType packType = new UPS_Shipping_Rate.UPSRateService.CodeDescriptionType(); packType.Code = "02"; package.PackagingType = packType; pkgArray[nrBoxes] = package; }
private void AddPackageArray(int nrBoxes, int itemsInLastBox, string fullBoxWeight, string partialBoxWeight, int valuePerFullBox, int valuePerPartialBox, inv_detl details, ShipmentType shipment) { PackageType[] pkgArray; if (itemsInLastBox > 0) pkgArray = new PackageType[nrBoxes + 1]; else pkgArray = new PackageType[nrBoxes]; for (int i = 0; i < nrBoxes; i++) { AddFullPackage(fullBoxWeight, valuePerFullBox, details, pkgArray, i); } if (itemsInLastBox > 0 && !string.IsNullOrEmpty(partialBoxWeight)) AddPartialPackage(nrBoxes, partialBoxWeight, valuePerPartialBox, details, pkgArray); shipment.Package = pkgArray; }
public ActionResult GetCost(string qty, string zipcode) { int BOX_CASE = 5; int CASE_WT = 5; int UT_WT = 1; int Qty = 100; int diff = 0; int nrBoxes = 0; int itemsInLastBox = 0; int valuePerFullBox = 0; int valuePerPartialBox = 0; decimal unitPrice = 14; string szError = ""; string szMsg = ""; string szItemId = "DF4011"; string fullBoxWeight = ""; string partialBoxWeight = ""; //UPSinv_detl details = null; inv_detl details = null; ITEM item = null; PRICE price = null; try { if (string.IsNullOrEmpty(qty)) { Qty = 50; } else { Qty = Convert.ToInt32(qty); } //details = new UPSinv_detl(); details = new inv_detl(); details.CASE_HI = 5; details.CASE_LEN = 5; details.CASE_WI = 5; price = db.PRICEs.Where(prc => prc.Item == szItemId && prc.Qty == Qty).FirstOrDefault<PRICE>(); if (price != null) { unitPrice = price.thePrice; } item = db.ITEMs.Where(itm => itm.ItemID == szItemId).FirstOrDefault<ITEM>(); if (item != null) { BOX_CASE = Convert.ToInt16(item.UnitPerCase); CASE_WT = Convert.ToInt32(item.CaseWeight); UT_WT = Convert.ToInt32(item.UnitWeight); details.CASE_HI = Convert.ToDecimal(item.CaseDimensionH); details.CASE_LEN = Convert.ToDecimal(item.CaseDimensionL); details.CASE_WT = Convert.ToDecimal(item.CaseDimensionW); //Sample uses details.CASE_WT } nrBoxes = Qty / BOX_CASE; itemsInLastBox = Qty % BOX_CASE; fullBoxWeight = CASE_WT.ToString(); if (itemsInLastBox > 0) { partialBoxWeight = (itemsInLastBox * UT_WT).ToString(); } valuePerFullBox = BOX_CASE * Convert.ToInt32(unitPrice); diff = valuePerFullBox % 100; if (diff > 0) { valuePerFullBox = valuePerFullBox + (100 - diff); } valuePerPartialBox = itemsInLastBox * Convert.ToInt32(unitPrice); diff = valuePerPartialBox % 100; if (diff > 0) { valuePerPartialBox = valuePerPartialBox + (100 - diff); } //GetRateFromUPS(Qty, nrBoxes, itemsInLastBox, fullBoxWeight, valuePerFullBox, valuePerPartialBox, partialBoxWeight, details, unitPrice); GetRateFromUPS(Qty, nrBoxes, itemsInLastBox, fullBoxWeight, valuePerFullBox, valuePerPartialBox, partialBoxWeight, details, unitPrice); } catch (Exception err) { szMsg = string.Format("{0} {1}", err.Message, err.StackTrace); } return View(); }
public ActionResult GetCost(string qty, string zipcode) { int BOX_CASE = 5; int CASE_WT = 5; int UT_WT = 1; int Qty = 100; int diff = 0; int nrBoxes = 0; int itemsInLastBox = 0; int valuePerFullBox = 0; int valuePerPartialBox = 0; decimal unitPrice = 14; string szError = ""; string szMsg = ""; string szItemId = "DF4011"; string fullBoxWeight = ""; string partialBoxWeight = ""; //UPSinv_detl details = null; inv_detl details = null; ITEM item = null; PRICE price = null; try { if (string.IsNullOrEmpty(qty)) { Qty = 50; } else { Qty = Convert.ToInt32(qty); } //details = new UPSinv_detl(); details = new inv_detl(); details.CASE_HI = 5; details.CASE_LEN = 5; details.CASE_WI = 5; price = db.PRICEs.Where(prc => prc.Item == szItemId && prc.Qty == Qty).FirstOrDefault <PRICE>(); if (price != null) { unitPrice = price.thePrice; } item = db.ITEMs.Where(itm => itm.ItemID == szItemId).FirstOrDefault <ITEM>(); if (item != null) { BOX_CASE = Convert.ToInt16(item.UnitPerCase); CASE_WT = Convert.ToInt32(item.CaseWeight); UT_WT = Convert.ToInt32(item.UnitWeight); details.CASE_HI = Convert.ToDecimal(item.CaseDimensionH); details.CASE_LEN = Convert.ToDecimal(item.CaseDimensionL); details.CASE_WT = Convert.ToDecimal(item.CaseDimensionW); //Sample uses details.CASE_WT } nrBoxes = Qty / BOX_CASE; itemsInLastBox = Qty % BOX_CASE; fullBoxWeight = CASE_WT.ToString(); if (itemsInLastBox > 0) { partialBoxWeight = (itemsInLastBox * UT_WT).ToString(); } valuePerFullBox = BOX_CASE * Convert.ToInt32(unitPrice); diff = valuePerFullBox % 100; if (diff > 0) { valuePerFullBox = valuePerFullBox + (100 - diff); } valuePerPartialBox = itemsInLastBox * Convert.ToInt32(unitPrice); diff = valuePerPartialBox % 100; if (diff > 0) { valuePerPartialBox = valuePerPartialBox + (100 - diff); } //GetRateFromUPS(Qty, nrBoxes, itemsInLastBox, fullBoxWeight, valuePerFullBox, valuePerPartialBox, partialBoxWeight, details, unitPrice); GetRateFromUPS(Qty, nrBoxes, itemsInLastBox, fullBoxWeight, valuePerFullBox, valuePerPartialBox, partialBoxWeight, details, unitPrice); } catch (Exception err) { szMsg = string.Format("{0} {1}", err.Message, err.StackTrace); } return(View()); }
private void GetRateFromUPS(int Qty, int nrBoxes, int itemsInLastBox, string fullBoxWeight, int valuePerFullBox, int valuePerPartialBox, string partialBoxWeight, inv_detl details, decimal unitPrice) { try { List <Result> lst = new List <Result>(); lst.Add(new Result() { service = "UPS Next Day Air®", code = "01" }); lst.Add(new Result() { service = "UPS Second Day Air®", code = "02" }); lst.Add(new Result() { service = "UPS Ground", code = "03" }); lst.Add(new Result() { service = "UPS Express", code = "07" }); lst.Add(new Result() { service = "UPS ExpeditedSM", code = "08" }); lst.Add(new Result() { service = "UPS Standard", code = "11" }); lst.Add(new Result() { service = "UPS Three-Day Select®", code = "12" }); lst.Add(new Result() { service = "UPS Next Day Air Saver®", code = "13" }); lst.Add(new Result() { service = "UPS Next Day Air® Early A.M. SM", code = "14" }); foreach (Result r in lst) { RateService upsService = new RateService(); try { RateResponse rateResponse = CallUPSRateRequest(r.code, Qty, nrBoxes, itemsInLastBox, fullBoxWeight, valuePerFullBox, valuePerPartialBox, partialBoxWeight, details, unitPrice, upsService); if (rateResponse.RatedShipment != null) { foreach (var rshipment in rateResponse.RatedShipment) { r.cost = rshipment.NegotiatedRateCharges.TotalCharge.MonetaryValue + " " + rshipment.NegotiatedRateCharges.TotalCharge.CurrencyCode; if (rshipment.GuaranteedDelivery != null && rshipment.GuaranteedDelivery.BusinessDaysInTransit != null) { r.time = rshipment.GuaranteedDelivery.BusinessDaysInTransit + " days"; } } } } catch (System.Web.Services.Protocols.SoapException ex) { } } //lstView.DataSource = lst; //lstView.DataBind(); //Display the response data ViewBag.ResultList = lst; } catch (System.Web.Services.Protocols.SoapException ex) { } }
private RateResponse CallUPSRateRequest(string scode, int Qty, int nrBoxes, int itemsInLastBox, string fullBoxWeight, int valuePerFullBox, int valuePerPartialBox, string partialBoxWeight, inv_detl details, decimal unitPrice, RateService upsService) { RateResponse rateResponse = new RateResponse(); try { RateRequest rateRequest = new RateRequest(); AddCustomerClassification(rateRequest); AddUpsSecurity(upsService); UPS_Shipping_Rate.UPSRateService.RequestType request = new RequestType(); String[] requestOption = { "Rate" }; request.RequestOption = requestOption; rateRequest.Request = request; ShipmentType shipment = new ShipmentType(); AddShipper(shipment); AddShipFromAddress(shipment); AddShipToAddress(shipment); UPS_Shipping_Rate.UPSRateService.CodeDescriptionType service = new UPS_Shipping_Rate.UPSRateService.CodeDescriptionType(); service.Code = scode.ToString(); shipment.Service = service; ShipmentRatingOptionsType optype = new ShipmentRatingOptionsType(); optype.NegotiatedRatesIndicator = string.Empty; shipment.ShipmentRatingOptions = optype; AddPackageArray(nrBoxes, itemsInLastBox, fullBoxWeight, partialBoxWeight, valuePerFullBox, valuePerPartialBox, details, shipment); AddInvoiceTotalType(Qty, unitPrice, shipment); rateRequest.Shipment = shipment; // ServicePointManager.ServerCertificateValidationCallback = ValidateRemoteCertificate; rateResponse = upsService.ProcessRate(rateRequest); } catch (Exception ex) { } return(rateResponse); }
private void AddPackageArray(int nrBoxes, int itemsInLastBox, string fullBoxWeight, string partialBoxWeight, int valuePerFullBox, int valuePerPartialBox, inv_detl details, ShipmentType shipment) { PackageType[] pkgArray; if (itemsInLastBox > 0) { pkgArray = new PackageType[nrBoxes + 1]; } else { pkgArray = new PackageType[nrBoxes]; } for (int i = 0; i < nrBoxes; i++) { AddFullPackage(fullBoxWeight, valuePerFullBox, details, pkgArray, i); } if (itemsInLastBox > 0 && !string.IsNullOrEmpty(partialBoxWeight)) { AddPartialPackage(nrBoxes, partialBoxWeight, valuePerPartialBox, details, pkgArray); } shipment.Package = pkgArray; }