Example #1
0
        public override Attempt <IShipmentRateQuote> QuoteShipment(IShipment shipment)
        {
            try
            {
                // TODO this should be made configurable
                var visitor = new FedExShipmentLineItemVisitor()
                {
                    UseOnSalePriceIfOnSale = false
                };

                shipment.Items.Accept(visitor);

                var province = ShipMethod.Provinces.FirstOrDefault(x => x.Code == shipment.ToRegion);

                var shippingPrice = 0M;
                try
                {
                    var service = new RateService {
                        Url = "https://wsbeta.fedex.com:443/web-services/rate"
                    };

                    var collection = GetCollectionFromCache(shipment);
                    if (collection == null)
                    {
                        var reply = service.getRates(RateRequest(shipment, visitor.TotalWeight, visitor.Quantity));



                        if (reply.HighestSeverity == NotificationSeverityType.SUCCESS || reply.HighestSeverity == NotificationSeverityType.NOTE || reply.HighestSeverity == NotificationSeverityType.WARNING)
                        {
                            collection = BuildDeliveryOptions(reply, shipment);

                            _runtimeCache.InsertCacheItem(MakeCacheKey(shipment), () => collection);
                        }
                    }

                    var firstCarrierRate = collection.FirstOrDefault(option => option.Service.Contains(_shipMethod.ServiceCode));
                    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 }));
            }
            catch (Exception ex)
            {
                return(Attempt <IShipmentRateQuote> .Fail(
                           new Exception("An error occured during your request : " +
                                         ex.Message +
                                         " Please contact your administrator or try again.")));
            }
        }
        public override Attempt<IShipmentRateQuote> QuoteShipment(IShipment shipment)
        {
            try
            {
                // TODO this should be made configurable
                var visitor = new FedExShipmentLineItemVisitor() { UseOnSalePriceIfOnSale = false };

                shipment.Items.Accept(visitor);

                var province = ShipMethod.Provinces.FirstOrDefault(x => x.Code == shipment.ToRegion);

                var shippingPrice = 0M;
                try
                {
                    var service = new RateService { Url = "https://wsbeta.fedex.com:443/web-services/rate" };

                    var collection = GetCollectionFromCache(shipment);
                    if (collection == null)
                    {
                        var reply = service.getRates(RateRequest(shipment, visitor.TotalWeight, visitor.Quantity));



                        if (reply.HighestSeverity == NotificationSeverityType.SUCCESS || reply.HighestSeverity == NotificationSeverityType.NOTE || reply.HighestSeverity == NotificationSeverityType.WARNING)
                        {
                            collection = BuildDeliveryOptions(reply, shipment);

                            _runtimeCache.InsertCacheItem(MakeCacheKey(shipment), () => collection);       
                        }
                    }

                    var firstCarrierRate = collection.FirstOrDefault(option => option.Service.Contains(_shipMethod.ServiceCode));
                    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 });
            }
            catch (Exception ex)
            {
                return Attempt<IShipmentRateQuote>.Fail(
                           new Exception("An error occured during your request : " +
                                                        ex.Message +
                                                        " Please contact your administrator or try again."));
            }
        }