public Attempt <IShipmentRateQuote> CalculatePrice(IShipment shipment, IShipMethod shipMethod, decimal totalWeight, IShipProvince province) { // First sum up the total weight for the shipment. // We're assumning that a custom order line property // was set on the order line prior when the product was added to the order line. var shippingPrice = 0M; try { var http = new UpsHttpRequestHandler(); var rateXml = http.Post(RateRequest(shipment, totalWeight)); var collection = UpsParseRates(rateXml); var firstCarrierRate = collection.FirstOrDefault(option => option.Service == shipMethod.Name); if (firstCarrierRate != null) { shippingPrice = firstCarrierRate.Rate; } } catch (Exception ex) { return(Attempt <IShipmentRateQuote> .Fail( new Exception("An error occured during your request : " + ex.Message + " Please contact your administrator or try again."))); } return(Attempt <IShipmentRateQuote> .Succeed(new ShipmentRateQuote(shipment, shipMethod) { Rate = shippingPrice })); }
public Attempt<IShipmentRateQuote> CalculatePrice(IShipment shipment, IShipMethod shipMethod, decimal totalWeight, IShipProvince province) { // First sum up the total weight for the shipment. // We're assumning that a custom order line property // was set on the order line prior when the product was added to the order line. var shippingPrice = 0M; try { var http = new UpsHttpRequestHandler(); var rateXml = http.Post(RateRequest(shipment, totalWeight)); var collection = UpsParseRates(rateXml); var firstCarrierRate = collection.FirstOrDefault(option => option.Service == shipMethod.Name); if (firstCarrierRate != null) shippingPrice = firstCarrierRate.Rate; } catch (Exception ex) { return Attempt<IShipmentRateQuote>.Fail( new Exception("An error occured during your request : " + ex.Message + " Please contact your administrator or try again.")); } return Attempt<IShipmentRateQuote>.Succeed(new ShipmentRateQuote(shipment, shipMethod) { Rate = shippingPrice }); }