Exemple #1
0
        static void Main(string[] args)
        {
            RateRequest request = CreateRateRequest();
            //
            RateService service = new RateService();

            if (usePropertyFile())
            {
                service.Url = getProperty("endpoint");
            }
            try
            {
                // Call the web service passing in a RateRequest and returning a RateReply
                RateReply reply = service.getRates(request);

                if (reply.HighestSeverity == NotificationSeverityType.SUCCESS || reply.HighestSeverity == NotificationSeverityType.NOTE || reply.HighestSeverity == NotificationSeverityType.WARNING)
                {
                    ShowRateReply(reply);
                }
                ShowNotifications(reply);
            }
            catch (SoapException e)
            {
                Console.WriteLine(e.Detail.InnerText);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            Console.WriteLine("Press any key to quit!");
            Console.ReadKey();
        }
Exemple #2
0
        public List <ShippingOption> GetShippingOptions()
        {
            var         shippingOptions = new List <ShippingOption>();
            RateRequest request         = CreateRateRequest();
            //
            var service = new RateService(); // Initialize the service

            try
            {
                // Call the web service passing in a RateRequest and returning a RateReply
                RateReply reply = service.getRates(request);

                if (reply.HighestSeverity == NotificationSeverityType.SUCCESS || reply.HighestSeverity == NotificationSeverityType.NOTE || reply.HighestSeverity == NotificationSeverityType.WARNING) // check if the call was successful
                {
                    shippingOptions = ParseAnswer(reply);
                }
                else
                {
                    Debug.LogError(new Exception(reply.Notifications[0].Message), false);
                }
            }
            catch (SoapException e)
            {
                Debug.LogError(e);
            }
            catch (Exception e)
            {
                Debug.LogError(e);
            }
            return(shippingOptions);
        }
Exemple #3
0
        public static double FedExEstimatedRate(Person shipto, ProductCollection cart)
        {
            double temp = 0.0;                                                //return 0.0 if something is wrong

            RateRequest request = FedEx.FedExCreateRateRequest(shipto, cart); //TODO:  better to use shoppingcartV2 if it was available
            RateService service = new RateService();                          // Initialize the service

            try
            {
                // Call the web service passing in a RateRequest and returning a RateReply
                RateReply reply = service.getRates(request);
                if (reply.HighestSeverity == NotificationSeverityType.SUCCESS || reply.HighestSeverity == NotificationSeverityType.NOTE || reply.HighestSeverity == NotificationSeverityType.WARNING) // check if the call was successful
                {
                    //ShowRateReply(reply);
                    for (int i = 0; i < reply.RateReplyDetails[0].RatedShipmentDetails.Count(); i++)
                    {
                        ShipmentRateDetail rateDetail = reply.RateReplyDetails[0].RatedShipmentDetails[i].ShipmentRateDetail;
                        if ((double)rateDetail.TotalNetCharge.Amount > temp)
                        {
                            temp = (double)rateDetail.TotalNetCharge.Amount;
                        }
                    }
                }
                FedEx.FedExShowNotifications(reply);
            }
            catch (Exception ex)
            {
                temp = 0.0;
            }
            return(temp);
        }
Exemple #4
0
        static void Main()
        {
            RateRequest request = CreateRateRequest();

            var service = new RateService();

            string productId = ConfigurationManager.AppSettings["productID"];

            if (productId == "Production")
            {
                service.Url = "https://ws.fedex.com:443/web-services/rate";
            }



            try
            {
                var reply = service.getRates(request);
                if (reply.HighestSeverity == NotificationSeverityType.SUCCESS || reply.HighestSeverity == NotificationSeverityType.NOTE || reply.HighestSeverity == NotificationSeverityType.WARNING)
                {
                    ShowRateReply(reply);
                }
                ShowNotifications(reply);
            }
            catch (SoapException e)
            {
                Console.WriteLine(e.Detail.InnerText);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            Console.WriteLine("Press any key to quit!");
            Console.ReadKey();
        }
Exemple #5
0
        private Dictionary <string, ProviderShipRateQuote> GetProviderQuotes(Warehouse origin, CommerceBuilder.Users.Address destination, PackageList packageList)
        {
            RateRequest request     = CreateRateRequest(origin, destination, packageList);
            RateService rateService = new RateService();
            RateReply   reply;

            this.RecordCommunication("FedExWS", CommunicationDirection.Send, new UTF8Encoding().GetString(XmlUtility.Serialize(request)));
            // This is the call to the web service passing in a RateRequest and returning a RateReply
            try
            {
                reply = rateService.getRates(request); // Service call
            }
            catch (System.Web.Services.Protocols.SoapException se)
            {
                Logger.Error("Soap Exception", se);
                Logger.Debug(se.Detail.InnerXml);
                return(new Dictionary <string, ProviderShipRateQuote>());
            }
            this.RecordCommunication("FedExWS", CommunicationDirection.Receive, new UTF8Encoding().GetString(XmlUtility.Serialize(reply)));

            if (reply.HighestSeverity == NotificationSeverityType.SUCCESS || reply.HighestSeverity == NotificationSeverityType.NOTE || reply.HighestSeverity == NotificationSeverityType.WARNING) // check if the call was successful
            {
                //ShowRateReply(reply);
                return(ParseRates(reply));
            }
            else
            {
                //Console.WriteLine(reply.Notifications[0].Message);
                return(new Dictionary <string, ProviderShipRateQuote>());
            }
        }
Exemple #6
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.")));
            }
        }
Exemple #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="input"></param>
        /// <param name="fedExClientPolicy"></param>
        /// <returns></returns>
        internal static List <KeyValuePair <string, decimal> > GetShippingRates(FedexReqestInput input, FedExClientPolicy fedExClientPolicy)
        {
            FedExClientPolicy = fedExClientPolicy;

            var request = CreateRateRequest(input);

            var service = new RateService();

            try
            {
                // Call the web service passing in a RateRequest and returning a RateReply
                var reply = service.getRates(request);

                if (reply.HighestSeverity == NotificationSeverityType.SUCCESS ||
                    reply.HighestSeverity == NotificationSeverityType.NOTE ||
                    reply.HighestSeverity == NotificationSeverityType.WARNING)
                {
                    return(ShowRateReply(reply));
                }
            }
            catch (SoapException e)
            {
                Console.WriteLine(e.Detail.InnerText);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            return(new List <KeyValuePair <string, decimal> >());
        }
        public override void GetRates()
        {
            RateRequest request = CreateRateRequest();
            var         service = new RateService();

            try
            {
                // Call the web service passing in a RateRequest and returning a RateReply
                RateReply reply = service.getRates(request);
                //
                if (reply.HighestSeverity == NotificationSeverityType.SUCCESS || reply.HighestSeverity == NotificationSeverityType.NOTE || reply.HighestSeverity == NotificationSeverityType.WARNING)
                {
                    ProcessReply(reply);
                }
                ShowNotifications(reply);
            }
            catch (SoapException e)
            {
                Debug.WriteLine(e.Detail.InnerText);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
            }
        }
Exemple #9
0
        public decimal GetRate(string weight, string shipperZipCode, string shipperCountryCode, string destinationZipCode, string destinationCountryCode, string serviceCode)
        {
            decimal rate = 0;
            // Build the RateRequest
            RateRequest request = new RateRequest();

            //
            request.WebAuthenticationDetail = new WebAuthenticationDetail();
            request.WebAuthenticationDetail.UserCredential          = new WebAuthenticationCredential();
            request.WebAuthenticationDetail.UserCredential.Key      = m_serviceKey;      // Replace "XXX" with the Key
            request.WebAuthenticationDetail.UserCredential.Password = m_servicePassword; // Replace "XXX" with the Password
            //
            request.ClientDetail = new ClientDetail();
            request.ClientDetail.AccountNumber = m_accountNumber; // Replace "XXX" with client's account number
            request.ClientDetail.MeterNumber   = m_meterNumber;   // Replace "XXX" with client's meter number
            //
            request.TransactionDetail = new TransactionDetail();
            request.TransactionDetail.CustomerTransactionId = "***Rate v7 Request using VC#***"; // This is a reference field for the customer.  Any value can be used and will be provided in the response.
            //
            request.Version = new VersionId();                                                   // WSDL version information, value is automatically set from wsdl
            //
            request.ReturnTransitAndCommit          = true;
            request.ReturnTransitAndCommitSpecified = true;
            request.CarrierCodes    = new CarrierCodeType[1];
            request.CarrierCodes[0] = CarrierCodeType.FDXE;

            //set the shipment details
            SetShipmentDetails(request, serviceCode);
            //Set the Origin
            SetOrigin(request, shipperZipCode, shipperCountryCode);
            //Set the Destination
            SetDestination(request, destinationZipCode, destinationCountryCode);

            //Set the Payment
            SetPayment(request);

            //Set the Summary
            SetSummaryPackageLineItems(request, weight);

            RateService service = new RateService(); // Initialize the service
            RateReply   reply   = service.getRates(request);

            if (reply.HighestSeverity == NotificationSeverityType.SUCCESS || reply.HighestSeverity == NotificationSeverityType.NOTE || reply.HighestSeverity == NotificationSeverityType.WARNING) // check if the call was successful
            {
                rate = reply.RateReplyDetails[0].RatedShipmentDetails[0].ShipmentRateDetail.TotalNetCharge.Amount;
            }

            return(rate);
        }
Exemple #10
0
        public List <ShippingRate> GetRates()
        {
            List <ShippingRate> result = new List <ShippingRate>();

            RateRequest request = new RateRequest();

            //
            request.WebAuthenticationDetail = new WebAuthenticationDetail();
            request.WebAuthenticationDetail.UserCredential          = new WebAuthenticationCredential();
            request.WebAuthenticationDetail.UserCredential.Key      = "Qc0L7y4hA4oXJl29";
            request.WebAuthenticationDetail.UserCredential.Password = "******";

            //
            request.ClientDetail = new ClientDetail();
            request.ClientDetail.AccountNumber = "510087500";
            request.ClientDetail.MeterNumber   = "119056534";

            //
            request.TransactionDetail = new TransactionDetail();
            request.TransactionDetail.CustomerTransactionId = "***Rate Available Services Request using VC#***"; // This is a reference field for the customer.  Any value can be used and will be provided in the response.
            //
            request.Version = new VersionId();
            //
            request.ReturnTransitAndCommit          = true;
            request.ReturnTransitAndCommitSpecified = true;
            //
            SetShipmentDetails(request);
            //

            RateService service = new RateService();
            RateReply   reply   = service.getRates(request);

            if (reply.HighestSeverity == NotificationSeverityType.SUCCESS || reply.HighestSeverity == NotificationSeverityType.NOTE || reply.HighestSeverity == NotificationSeverityType.WARNING)
            {
                foreach (var item in reply.RateReplyDetails)
                {
                    result.Add(new ShippingRate()
                    {
                        Method = item.ServiceType.ToString(),
                        Price  = item.RatedShipmentDetails[0].ShipmentRateDetail.TotalNetCharge.Amount,
                    });
                }
            }

            return(result);
        }
        public Attempt <IShipmentRateQuote> CalculatePrice(IShipment shipment, IShipMethod shipMethod, decimal totalWeight, int quantity, 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 service = new RateService {
                    Url = "https://wsbeta.fedex.com:443/web-services/rate"
                };

                var reply = service.getRates(RateRequest(shipment, totalWeight, quantity));

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

                    var firstCarrierRate = collection.FirstOrDefault(option => option.Service.Contains(shipMethod.ServiceCode.Split('-').First()));
                    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 }));
        }
Exemple #12
0
        /// <summary>
        ///  Gets available shipping options
        /// </summary>
        /// <param name="getShippingOptionRequest">A request for getting shipping options</param>
        /// <returns>Represents a response of getting shipping rate options</returns>
        public GetShippingOptionResponse GetShippingOptions(GetShippingOptionRequest getShippingOptionRequest)
        {
            if (getShippingOptionRequest == null)
            {
                throw new ArgumentNullException("getShippingOptionRequest");
            }

            var response = new GetShippingOptionResponse();

            if (getShippingOptionRequest.Items == null)
            {
                response.AddError(T("Admin.System.Warnings.NoShipmentItems"));
                return(response);
            }

            if (getShippingOptionRequest.ShippingAddress == null || getShippingOptionRequest.ShippingAddress.Country == null)
            {
                return(response);
            }

            Currency requestedShipmentCurrency;
            var      request = CreateRateRequest(getShippingOptionRequest, out requestedShipmentCurrency);
            var      service = new RateService(); // Initialize the service

            service.Url = _fedexSettings.Url;

            try
            {
                // This is the call to the web service passing in a RateRequest and returning a RateReply
                var reply = service.getRates(request); // Service call

                if (reply.HighestSeverity == RateServiceWebReference.NotificationSeverityType.SUCCESS ||
                    reply.HighestSeverity == RateServiceWebReference.NotificationSeverityType.NOTE ||
                    reply.HighestSeverity == RateServiceWebReference.NotificationSeverityType.WARNING) // check if the call was successful
                {
                    if (reply != null && reply.RateReplyDetails != null)
                    {
                        var shippingOptions = ParseResponse(reply, requestedShipmentCurrency);
                        foreach (var shippingOption in shippingOptions)
                        {
                            response.ShippingOptions.Add(shippingOption);
                        }
                    }
                    else
                    {
                        if (reply != null &&
                            reply.Notifications != null &&
                            reply.Notifications.Length > 0 &&
                            !String.IsNullOrEmpty(reply.Notifications[0].Message))
                        {
                            response.AddError(string.Format("{0} (code: {1})", reply.Notifications[0].Message, reply.Notifications[0].Code));
                            return(response);
                        }
                        else
                        {
                            response.AddError("Could not get reply from shipping server");
                            return(response);
                        }
                    }
                }
                else
                {
                    Debug.WriteLine(reply.Notifications[0].Message);
                    response.AddError(reply.Notifications[0].Message);
                    return(response);
                }
            }
            catch (SoapException e)
            {
                Debug.WriteLine(e.Detail.InnerText);
                response.AddError(e.Detail.InnerText);
                return(response);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
                response.AddError(e.Message);
                return(response);
            }

            return(response);
        }
Exemple #13
0
        public decimal GetPrice(Delivery delivery, string currencyCode)
        {
            decimal decRate = 0;

            try
            {
                ServiceType stType = new ServiceType();
                switch (delivery.ShippingOption.ShippingOptionName)
                {
                case "FedExPriorityOvernight":
                    stType = ServiceType.PRIORITY_OVERNIGHT;
                    break;

                case "FedExStandardOvernight":
                    stType = ServiceType.STANDARD_OVERNIGHT;
                    break;
                }

                CurrentUserInfo uinfo = MembershipContext.AuthenticatedUser;

                RateReply reply = new RateReply();
                // Cache the data for 10 minutes with a key
                using (CachedSection <RateReply> cs = new CachedSection <RateReply>(ref reply, 60, true, null, "FexExRatesAPI-" + stType.ToString().Replace(" ", "-") + uinfo.UserID + "-" + delivery.DeliveryAddress.AddressZip + "-" + ValidationHelper.GetString(delivery.Weight, "")))
                {
                    if (cs.LoadData)
                    {
                        //Create the request
                        RateRequest request = CreateRateRequest(delivery, stType);
                        //Create the service
                        RateService service = new RateService();
                        // Call the web service passing in a RateRequest and returning a RateReply
                        reply   = service.getRates(request);
                        cs.Data = reply;
                    }
                    reply = cs.Data;
                }

                if (reply.HighestSeverity == NotificationSeverityType.SUCCESS)
                {
                    foreach (RateReplyDetail repDetail in reply.RateReplyDetails)
                    {
                        foreach (RatedShipmentDetail rsd in repDetail.RatedShipmentDetails)
                        {
                            //Add an offset to handle the differencse in the testing envinronment
                            decRate = ValidationHelper.GetDecimal(rsd.ShipmentRateDetail.TotalNetFedExCharge.Amount * 1.08m, 0);
                        }
                    }
                }
                else
                {
                    //Clean up the cached value so the next time the value is pulled again
                    CacheHelper.ClearCache("FexExRatesAPI-" + stType.ToString().Replace(" ", "-") + uinfo.UserID + "-" + delivery.DeliveryAddress.AddressZip + "-" + ValidationHelper.GetString(delivery.Weight, ""));
                }
            }
            catch (Exception ex)
            {
                //Log the error
                EventLogProvider.LogException("FedExCarrier - GetPrice", "EXCEPTION", ex);
                //Set some base rate for the shipping
                decRate = 10;
            }
            return(decRate);
        }
Exemple #14
0
        public static ShippingResponse GetRate(string dataType = "json")
        {
            try {
                if (dataType.ToUpper() == "JSON" || dataType.ToUpper() == "JSONP") {
                    ValidateJSON();
                } else {
                    ValidateXML();
                }

                RateRequest standardRequest = CreateRateRequest(_auth);
                RateRequest freightRequest = CreateRateRequest(_auth);
                standardRequest.RequestedShipment.FreightShipmentDetail = null;
                freightRequest.RequestedShipment.RequestedPackageLineItems = null;
                RateService service = new RateService(_environment); // Initializes the service
                try {
                    // Call the web service passing in a RateRequest and returing a RateReply
                    decimal totalweight = standardRequest.RequestedShipment.RequestedPackageLineItems.Sum(x => x.Weight.Value);
                    RateReply reply = new RateReply();
                    if (totalweight < 90) {
                        reply = service.getRates(standardRequest);
                    } else if (totalweight >= 150) {
                        //reply = service.getRates(freightRequest);
                        reply = service.getRates(standardRequest);
                    } else {
                        // make both calls
                        reply = service.getRates(standardRequest);
                        /*RateReply freightreply = service.getRates(freightRequest);

                        List<Notification> allnotifications = new List<Notification>();
                        List<RateReplyDetail> alldetails = new List<RateReplyDetail>();

                        if (standardreply.HighestSeverity == NotificationSeverityType.SUCCESS || standardreply.HighestSeverity == NotificationSeverityType.NOTE || standardreply.HighestSeverity == NotificationSeverityType.WARNING) {
                            reply.HighestSeverity = standardreply.HighestSeverity;
                            allnotifications.AddRange(standardreply.Notifications.ToList<Notification>());
                            alldetails.AddRange(standardreply.RateReplyDetails.ToList<RateReplyDetail>());
                            reply.TransactionDetail = standardreply.TransactionDetail;
                            reply.Version = standardreply.Version;
                        }

                        if (freightreply.HighestSeverity == NotificationSeverityType.SUCCESS || freightreply.HighestSeverity == NotificationSeverityType.NOTE || freightreply.HighestSeverity == NotificationSeverityType.WARNING) {
                            reply.HighestSeverity = freightreply.HighestSeverity;
                            allnotifications.AddRange(freightreply.Notifications.ToList<Notification>());
                            alldetails.AddRange(freightreply.RateReplyDetails.ToList<RateReplyDetail>());
                            reply.TransactionDetail = freightreply.TransactionDetail;
                            reply.Version = freightreply.Version;
                        }
                        reply.Notifications = allnotifications.ToArray<Notification>();
                        reply.RateReplyDetails = alldetails.ToArray<RateReplyDetail>();*/

                    }

                    ShippingResponse resp = new ShippingResponse();

                    // Check if the call was successful
                    if (reply.HighestSeverity == NotificationSeverityType.SUCCESS || reply.HighestSeverity == NotificationSeverityType.NOTE || reply.HighestSeverity == NotificationSeverityType.WARNING) {
                        List<ShipmentRateDetails> details = new List<ShipmentRateDetails>();
                        details = GetRateDetails(reply);
                        resp = new ShippingResponse {
                            Status = "OK",
                            Status_Description = "",
                            Result = details
                        };
                    } else {
                        List<ShipmentRateDetails> details = new List<ShipmentRateDetails>();
                        ShipmentRateDetails detail = new ShipmentRateDetails();
                        detail.Notifications = ShowNotifications(reply);
                        details.Add(detail);
                        resp = new ShippingResponse {
                            Status = "ERROR",
                            Status_Description = "",
                            Result = details
                        };
                    }
                    return resp;
                } catch (SoapException e) {
                    throw new Exception(e.Detail.InnerText);
                } catch (Exception e) {
                    throw new Exception(e.Message);
                }
            } catch (Exception e) {
                ShippingResponse resp2 = new ShippingResponse {
                    Status = "ERROR",
                    Status_Description = e.Message,
                    Result = null
                };
                return resp2;
            }
        }
Exemple #15
0
        private void FedExGetRates(Shipments AllShipments, out string RTShipRequest, out string RTShipResponse, decimal ExtraFee, Decimal MarkupPercent, decimal ShipmentValue, decimal ShippingTaxRate)        // Retrieves FedEx rates
        {
            RTShipRequest  = string.Empty;
            RTShipResponse = string.Empty;

            Decimal maxWeight = AppLogic.AppConfigUSDecimal("RTShipping.Fedex.MaxWeight");

            if (maxWeight == 0)
            {
                maxWeight = 150;
            }

            if (ShipmentWeight > maxWeight)
            {
                SM.ErrorMsg = "FedEx " + AppLogic.AppConfig("RTShipping.CallForShippingPrompt");
                return;
            }

            foreach (Packages Shipment in AllShipments)
            {
                foreach (Package p in Shipment)
                {
                    if (p.IsFreeShipping)
                    {
                        HasFreeItems = true;
                        break;
                    }
                }

                RateRequest request = CreateRateRequest(Shipment);
                RateService service = new RateService(); // Initialize the service
                service.Url = this.FedexServer;
                try
                {
                    RateReply reply = service.getRates(request);

                    string rateRequest = SerializeObject(request);
                    string rateReply   = SerializeObject(reply);
                    System.Diagnostics.Debug.WriteLine(rateRequest);
                    System.Diagnostics.Debug.WriteLine(rateReply);

                    if (reply.RateReplyDetails != null && (reply.HighestSeverity == NotificationSeverityType.SUCCESS || reply.HighestSeverity == NotificationSeverityType.NOTE || reply.HighestSeverity == NotificationSeverityType.WARNING))// check if the call was successful
                    {
                        //create list of available services

                        for (int i = 0; i < reply.RateReplyDetails.Length; i++)
                        {
                            RateReplyDetail rateReplyDetail = reply.RateReplyDetails[i];

                            // listRatedShipmentDetail is currently unused - could be used in the future to support list or pro-rated rates
                            RatedShipmentDetail listRatedShipmentDetail = rateReplyDetail.RatedShipmentDetails
                                                                          .FirstOrDefault(rsd => rsd.ShipmentRateDetail.RateType == ReturnedRateType.PAYOR_LIST_PACKAGE ||
                                                                                          rsd.ShipmentRateDetail.RateType == ReturnedRateType.RATED_LIST_PACKAGE ||
                                                                                          rsd.ShipmentRateDetail.RateType == ReturnedRateType.PAYOR_LIST_SHIPMENT ||
                                                                                          rsd.ShipmentRateDetail.RateType == ReturnedRateType.RATED_LIST_SHIPMENT);

                            RatedShipmentDetail ratedShipmentDetail = rateReplyDetail.RatedShipmentDetails
                                                                      .FirstOrDefault(rsd => rsd.ShipmentRateDetail.RateType == ReturnedRateType.PAYOR_ACCOUNT_PACKAGE ||
                                                                                      rsd.ShipmentRateDetail.RateType == ReturnedRateType.PAYOR_ACCOUNT_SHIPMENT ||
                                                                                      rsd.ShipmentRateDetail.RateType == ReturnedRateType.RATED_ACCOUNT_PACKAGE ||
                                                                                      rsd.ShipmentRateDetail.RateType == ReturnedRateType.RATED_ACCOUNT_SHIPMENT);

                            string rateName = "FedEx " + FedExGetCodeDescription(rateReplyDetail.ServiceType.ToString());

                            if (ShippingMethodIsAllowed(rateName, "FEDEX"))
                            {
                                decimal totalCharges = ratedShipmentDetail.ShipmentRateDetail.TotalNetCharge.Amount;

                                //multiply the returned rate by the quantity in the package to avoid calling
                                //more than necessary if there were multiple IsShipSeparately items
                                //ordered.  If there weren't, Shipment.PackageCount is 1 and the rate is normal
                                totalCharges = totalCharges * Shipment.PackageCount;

                                if (MarkupPercent != System.Decimal.Zero)
                                {
                                    totalCharges = Decimal.Round(totalCharges * (1.00M + (MarkupPercent / 100.0M)), 2, MidpointRounding.AwayFromZero);
                                }

                                decimal vat = Decimal.Round(totalCharges * ShippingTaxRate, 2, MidpointRounding.AwayFromZero);

                                if (!SM.MethodExists(rateName))
                                {
                                    ShipMethod s_method = new ShipMethod();

                                    s_method.Carrier     = "FEDEX";
                                    s_method.ServiceName = rateName;
                                    s_method.ServiceRate = totalCharges;
                                    s_method.VatRate     = vat;

                                    if (HasFreeItems)
                                    {
                                        s_method.FreeItemsRate = totalCharges;
                                    }

                                    SM.AddMethod(s_method);
                                }
                                else
                                {
                                    int        IndexOf  = SM.GetIndex(rateName);
                                    ShipMethod s_method = SM[IndexOf];

                                    s_method.ServiceRate += totalCharges;
                                    s_method.VatRate     += vat;

                                    if (HasFreeItems)
                                    {
                                        s_method.FreeItemsRate += totalCharges;
                                    }

                                    SM[IndexOf] = s_method;
                                }
                            }
                        }

                        // Handling fee should only be added per shipping address not per package
                        // let's just compute it here after we've gone through all the packages.
                        // Also, since we can't be sure about the ordering of the method call here
                        // and that the collection SM includes shipping methods from all possible carriers
                        // we'll need to filter out the methods per this carrier to avoid side effects on the main collection
                        foreach (ShipMethod shipMethod in SM.PerCarrier("FEDEX"))
                        {
                            shipMethod.ServiceRate += ExtraFee;
                        }
                    }
                    else
                    {
                        RTShipResponse = "Error: Call Not Successful " + reply.Notifications[0].Message;
                    }

                    RTShipRequest  = Serialize(request);
                    RTShipResponse = Serialize(reply);
                }
                catch (SoapException e)
                {
                    RTShipResponse = "FedEx Error: " + e.Detail.InnerXml;
                }
                catch (Exception e)
                {
                    RTShipResponse = "FedEx Error: " + e.InnerException.Message;
                }
            }
        }
Exemple #16
0
        private void FedExGetRates(Packages Shipment, out string RTShipRequest, out string RTShipResponse, decimal ExtraFee, Decimal MarkupPercent, decimal ShipmentValue, decimal ShippingTaxRate)     // Retrieves FedEx rates
        {
            RTShipRequest  = string.Empty;
            RTShipResponse = string.Empty;

            Hashtable   htRates = new Hashtable();
            RateRequest request = CreateRateRequest(Shipment);
            RateService service = new RateService(); // Initialize the service

            service.Url = this.FedexServer;


            try
            {
                // Call the web service passing in a RateRequest and returning a RateReply
                RateReply reply = service.getRates(request);

                if (reply.HighestSeverity == NotificationSeverityType.SUCCESS || reply.HighestSeverity == NotificationSeverityType.NOTE || reply.HighestSeverity == NotificationSeverityType.WARNING) // check if the call was successful
                {
                    //create list of available services

                    for (int i = 0; i < reply.RateReplyDetails.Length; i++)
                    {
                        RateReplyDetail     rateReplyDetail     = reply.RateReplyDetails[i];
                        RatedShipmentDetail ratedShipmentDetail = rateReplyDetail.RatedShipmentDetails[1];

                        decimal totalCharges = ratedShipmentDetail.ShipmentRateDetail.TotalNetCharge.Amount;
                        if (MarkupPercent != System.Decimal.Zero)
                        {
                            totalCharges = Decimal.Round(totalCharges * (1.00M + (MarkupPercent / 100.0M)), 2, MidpointRounding.AwayFromZero);
                        }

                        decimal vat      = Decimal.Round(totalCharges * ShippingTaxRate, 2, MidpointRounding.AwayFromZero);
                        string  rateName = rateReplyDetail.ServiceType.ToString();
                        if (htRates.ContainsKey(rateName))
                        {
                            // Get the sum of the rate(s)
                            decimal myTempCharge = Localization.ParseUSDecimal(htRates[rateName].ToString().Split('|')[0]);
                            totalCharges += myTempCharge;
                            vat          += Localization.ParseUSDecimal(htRates[rateName].ToString().Split('|')[1]);

                            // Remove the old value & add the new
                            htRates.Remove(rateName);
                        }

                        // Temporarily add rate to hash table
                        htRates.Add(rateName, Localization.CurrencyStringForDBWithoutExchangeRate(totalCharges) + "|" + Localization.CurrencyStringForDBWithoutExchangeRate(vat));
                    }
                }
                else
                {
                    ratesText.Add("Error: Call Not Successful");
                    ratesValues.Add("Error: Call Not Successful");
                }

                RTShipRequest  = Serialize(request);
                RTShipResponse = Serialize(reply);
            }
            catch (SoapException e)
            {
                ratesText.Add("Error: " + e.Detail.InnerText);
                ratesValues.Add("Error: " + e.Detail.InnerText);
            }
            catch (Exception e)
            {
                ratesText.Add("Error: " + e.Message);
                ratesValues.Add("Error: " + e.Message);
            }



            // Add rates from hastable into array(s)
            IDictionaryEnumerator myEnumerator = htRates.GetEnumerator();

            while (myEnumerator.MoveNext())
            {
                Decimal tmp_rate = Localization.ParseUSDecimal(myEnumerator.Value.ToString().Substring(0, myEnumerator.Value.ToString().IndexOf("|"))) + ExtraFee;
                Decimal tmp_vat  = Localization.ParseUSDecimal(myEnumerator.Value.ToString().Substring(myEnumerator.Value.ToString().LastIndexOf("|") + 1));
                String  rateText = tmp_rate.ToString() + "|" + tmp_vat.ToString();
                ratesText.Add(myEnumerator.Key.ToString() + " $" + rateText);
                ratesValues.Add(myEnumerator.Key.ToString() + "|" + rateText);
            }
        }
Exemple #17
0
        /// <summary>
        ///  Gets available shipping options
        /// </summary>
        /// <param name="shipmentPackage">Shipment package</param>
        /// <param name="error">Error</param>
        /// <returns>Shipping options</returns>
        public ShippingOptionCollection GetShippingOptions(ShipmentPackage shipmentPackage, ref string error)
        {
            var shippingOptions = new ShippingOptionCollection();

            if (shipmentPackage == null)
            {
                throw new ArgumentNullException("shipmentPackage");
            }
            if (shipmentPackage.Items == null)
            {
                throw new NopException("No shipment items");
            }
            if (shipmentPackage.ShippingAddress == null)
            {
                error = "Shipping address is not set";
                return(shippingOptions);
            }
            if (shipmentPackage.ShippingAddress.Country == null)
            {
                error = "Shipping country is not set";
                return(shippingOptions);
            }

            RateRequest request = CreateRateRequest(shipmentPackage);
            RateService service = new RateService(); // Initialize the service

            service.Url = SettingManager.GetSettingValue("ShippingRateComputationMethod.FedEx.URL");
            try
            {
                // This is the call to the web service passing in a RateRequest and returning a RateReply
                var reply = service.getRates(request);                                                                                                                                                // Service call

                if (reply.HighestSeverity == NotificationSeverityType.SUCCESS || reply.HighestSeverity == NotificationSeverityType.NOTE || reply.HighestSeverity == NotificationSeverityType.WARNING) // check if the call was successful
                {
                    if (reply != null && reply.RateReplyDetails != null)
                    {
                        shippingOptions = ParseResponse(reply);
                    }
                    else
                    {
                        error = "Could not get reply from shipping server";
                    }
                }
                else
                {
                    Debug.WriteLine(reply.Notifications[0].Message);
                    error = reply.Notifications[0].Message;
                }
            }
            catch (SoapException e)
            {
                Debug.WriteLine(e.Detail.InnerText);
                error = e.Detail.InnerText;
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
                error = e.Message;
            }

            return(shippingOptions);
        }
Exemple #18
0
        public List <ShippingRate> GetShipmentRates(Shipment shippingDetail)
        {
            System.Threading.Thread.Sleep(3000);
            return(new List <ShippingRate>()
            {
                new ShippingRate {
                    PackageType = "Package", MailClass = "FedEx Ground", MailService = "Parcel", Zone = "5", Pricing = "Retail", TotalAmount = 23.44m, DeliveryDate = new System.DateTime().AddDays(3)
                },
                new ShippingRate {
                    PackageType = "Package", MailClass = "FedEx Express", MailService = "Letter", Zone = "5", Pricing = "Retail", TotalAmount = 11.32m, DeliveryDate = new System.DateTime().AddDays(2)
                },
                new ShippingRate {
                    PackageType = "Package", MailClass = "FedEx Mail", MailService = "Enveloope", Zone = "5", Pricing = "Retail", TotalAmount = 12.25m, DeliveryDate = new System.DateTime().AddDays(5)
                },
            });

            // create request object
            var requetObject = RequestHelper.CreateRateRequest(shippingDetail);

            // send the request to get the rates
            var response = _service.getRates(requetObject);

            var results = new List <ShippingRate>();

            if (response.HighestSeverity == NotificationSeverityType.SUCCESS ||
                response.HighestSeverity == NotificationSeverityType.NOTE ||
                response.HighestSeverity == NotificationSeverityType.WARNING)
            {
                foreach (var rateReplyDetail in response.RateReplyDetails)
                {
                    foreach (var shipmentDetail in rateReplyDetail.RatedShipmentDetails)
                    {
                        if (shipmentDetail == null)
                        {
                            continue;
                        }
                        if (shipmentDetail.ShipmentRateDetail == null)
                        {
                            continue;
                        }
                        var rateDetail = shipmentDetail.ShipmentRateDetail;

                        results.Add(new ShippingRate
                        {
                            PackageType  = rateReplyDetail.PackagingType.ToString(),
                            TotalAmount  = rateDetail.TotalNetCharge.Amount,
                            MailClass    = rateReplyDetail.ServiceType.ToString(),
                            MailService  = parseServiceTypeCode(rateReplyDetail.ServiceType),
                            Pricing      = rateDetail.PricingCode.ToString(),
                            Zone         = rateDetail.RateZone,
                            DeliveryDate = rateReplyDetail.DeliveryTimestamp
                        });
                    }
                }
            }

            // log the notifications
            logNotifications(response);

            return(results);
        }
Exemple #19
0
        void FedExGetRates(Shipments shipments, out string rtShipRequest, out string rtShipResponse, decimal extraFee, decimal markupPercent, decimal shippingTaxRate, Cache cache, ref ShippingMethodCollection shippingMethods)
        {
            rtShipRequest  = string.Empty;
            rtShipResponse = string.Empty;

            var maxWeight = AppConfigProvider.GetAppConfigValueUsCulture <decimal>("RTShipping.Fedex.MaxWeight", StoreId, true);

            if (maxWeight == 0)
            {
                maxWeight = 150;
            }

            if (ShipmentWeight > maxWeight)
            {
                shippingMethods.ErrorMsg = "FedEx " + AppConfigProvider.GetAppConfigValue("RTShipping.CallForShippingPrompt", StoreId, true);
                return;
            }

            foreach (var shipment in shipments)
            {
                HasFreeItems = shipments
                               .SelectMany(packages => packages)
                               .Where(package => package.IsFreeShipping)
                               .Any();

                var rateRequest = CreateRateRequest(shipment);
                rtShipRequest = SerializeToString(rateRequest);

                string    cacheKey  = null;
                RateReply rateReply = null;
                if (cache != null)
                {
                    // Hash the content
                    var md5 = System.Security.Cryptography.MD5.Create();
                    using (var hashDataStream = new MemoryStream())
                    {
                        using (var hashDataWriter = new StreamWriter(hashDataStream, Encoding.UTF8, 1024, true))
                            hashDataWriter.Write(StripShipTimestampNode(rtShipRequest));

                        hashDataStream.Flush();
                        hashDataStream.Position = 0;

                        cacheKey = string.Format("RTShipping.FedEx.{0}", md5.ComputeHash(hashDataStream).ToString("-"));
                    }

                    // See if the cache contains the content
                    var cachedResponse = cache.Get(cacheKey) as RateReply;
                    if (cachedResponse != null)
                    {
                        rateReply = cachedResponse;
                    }
                }

                try
                {
                    if (rateReply == null)
                    {
                        var rateService = new RateService
                        {
                            Url = FedexServer,
                        };

                        rateReply      = rateService.getRates(rateRequest);
                        rtShipResponse = SerializeToString(rateReply);

                        if (cache != null && cacheKey != null)
                        {
                            cache.Insert(cacheKey, rateReply, null, DateTime.Now.AddMinutes(15), Cache.NoSlidingExpiration);
                        }
                    }

                    if (rateReply.RateReplyDetails == null ||
                        (rateReply.HighestSeverity != NotificationSeverityType.SUCCESS &&
                         rateReply.HighestSeverity != NotificationSeverityType.NOTE &&
                         rateReply.HighestSeverity != NotificationSeverityType.WARNING))
                    {
                        rtShipResponse = "Error: Call Not Successful " + rateReply.Notifications[0].Message;
                        return;
                    }

                    // Create a list of available services
                    foreach (var rateReplyDetail in rateReply.RateReplyDetails)
                    {
                        var ratedShipmentDetail = rateReplyDetail.RatedShipmentDetails
                                                  .Where(rsd => rsd.ShipmentRateDetail.RateType == ReturnedRateType.PAYOR_ACCOUNT_PACKAGE ||
                                                         rsd.ShipmentRateDetail.RateType == ReturnedRateType.PAYOR_ACCOUNT_SHIPMENT ||
                                                         rsd.ShipmentRateDetail.RateType == ReturnedRateType.RATED_ACCOUNT_PACKAGE ||
                                                         rsd.ShipmentRateDetail.RateType == ReturnedRateType.RATED_ACCOUNT_SHIPMENT)
                                                  .FirstOrDefault();

                        var rateName = string.Format("FedEx {0}", FedExGetCodeDescription(rateReplyDetail.ServiceType.ToString()));

                        if (!ShippingMethodIsAllowed(rateName, FedExName))
                        {
                            continue;
                        }

                        var totalCharges = ratedShipmentDetail.ShipmentRateDetail.TotalNetCharge.Amount;

                        // Multiply the returned rate by the quantity in the package to avoid calling
                        // more than necessary if there were multiple IsShipSeparately items
                        // ordered.  If there weren't, Shipment.PackageCount is 1 and the rate is normal.
                        totalCharges = totalCharges * shipment.PackageCount;

                        if (markupPercent != 0)
                        {
                            totalCharges = decimal.Round(totalCharges * (1 + (markupPercent / 100m)), 2, MidpointRounding.AwayFromZero);
                        }

                        var vat = decimal.Round(totalCharges * shippingTaxRate, 2, MidpointRounding.AwayFromZero);

                        if (!shippingMethods.MethodExists(rateName))
                        {
                            var shippingMethod = new ShippingMethod
                            {
                                Carrier    = FedExName,
                                Name       = rateName,
                                Freight    = totalCharges,
                                VatRate    = vat,
                                IsRealTime = true,
                                Id         = Shipping.GetShippingMethodID(rateName),
                            };

                            if (HasFreeItems)
                            {
                                shippingMethod.FreeItemsRate = totalCharges;
                            }

                            shippingMethods.Add(shippingMethod);
                        }
                        else
                        {
                            var shippingMethodIndex = shippingMethods.GetIndex(rateName);
                            var shippingMethod      = shippingMethods[shippingMethodIndex];

                            shippingMethod.Freight += totalCharges;
                            shippingMethod.VatRate += vat;

                            if (HasFreeItems)
                            {
                                shippingMethod.FreeItemsRate += totalCharges;
                            }

                            shippingMethods[shippingMethodIndex] = shippingMethod;
                        }
                    }

                    // Handling fee should only be added per shipping address not per package
                    // let's just compute it here after we've gone through all the packages.
                    // Also, since we can't be sure about the ordering of the method call here
                    // and that the collection SM includes shipping methods from all possible carriers
                    // we'll need to filter out the methods per this carrier to avoid side effects on the main collection
                    foreach (var shippingMethod in shippingMethods.PerCarrier(FedExName))
                    {
                        if (shippingMethod.Freight != 0)                        //Don't add the fee to free methods.
                        {
                            shippingMethod.Freight += extraFee;
                        }
                    }
                }
                catch (SoapException exception)
                {
                    rtShipResponse = "FedEx Error: " + exception.Detail.InnerXml;
                }
                catch (Exception exception)
                {
                    while (exception.InnerException != null)
                    {
                        exception = exception.InnerException;
                    }

                    rtShipResponse = "FedEx Error: " + exception.Message;
                }
            }
        }
Exemple #20
0
        public decimal GetPrice(Delivery delivery, string currencyCode)
        {
            decimal decRate = 0;
            try
            {
                ServiceType stType = new ServiceType();
                switch (delivery.ShippingOption.ShippingOptionName)
                {
                    case "FedExPriorityOvernight":
                        stType = ServiceType.PRIORITY_OVERNIGHT;
                        break;
                    case "FedExStandardOvernight":
                        stType = ServiceType.STANDARD_OVERNIGHT;
                        break;
                }

                CurrentUserInfo uinfo = MembershipContext.AuthenticatedUser;

                RateReply reply = new RateReply();
                // Cache the data for 10 minutes with a key
                using (CachedSection<RateReply> cs = new CachedSection<RateReply>(ref reply, 60, true, null, "FexExRatesAPI-" + stType.ToString().Replace(" ", "-") + uinfo.UserID + "-" + delivery.DeliveryAddress.AddressZip + "-" + ValidationHelper.GetString(delivery.Weight, "")))
                {
                    if (cs.LoadData)
                    {
                        //Create the request
                        RateRequest request = CreateRateRequest(delivery, stType);
                        //Create the service
                        RateService service = new RateService();
                        // Call the web service passing in a RateRequest and returning a RateReply
                        reply = service.getRates(request);
                        cs.Data = reply;
                    }
                    reply = cs.Data;
                }

                if (reply.HighestSeverity == NotificationSeverityType.SUCCESS)
                {
                    foreach (RateReplyDetail repDetail in reply.RateReplyDetails)
                    {
                        foreach (RatedShipmentDetail rsd in repDetail.RatedShipmentDetails)
                        {
                            //Add an offset to handle the differencse in the testing envinronment
                            decRate = ValidationHelper.GetDecimal(rsd.ShipmentRateDetail.TotalNetFedExCharge.Amount * 1.08m, 0);
                        }
                    }
                }
                else
                {
                    //Clean up the cached value so the next time the value is pulled again
                    CacheHelper.ClearCache("FexExRatesAPI-" + stType.ToString().Replace(" ", "-") + uinfo.UserID + "-" + delivery.DeliveryAddress.AddressZip + "-" + ValidationHelper.GetString(delivery.Weight, ""));
                }
            }
            catch (Exception ex)
            {
                //Log the error
                EventLogProvider.LogException("FedExCarrier - GetPrice", "EXCEPTION", ex);
                //Set some base rate for the shipping
                decRate = 10;
            }
            return decRate;
        }
Exemple #21
0
        public List<ShippingOption> GetShippingOptions()
        {
            var shippingOptions = new List<ShippingOption>();
            RateRequest request = CreateRateRequest();
            //
            var service = new RateService(); // Initialize the service
            try
            {
                // Call the web service passing in a RateRequest and returning a RateReply
                RateReply reply = service.getRates(request);

                if (reply.HighestSeverity == NotificationSeverityType.SUCCESS || reply.HighestSeverity == NotificationSeverityType.NOTE || reply.HighestSeverity == NotificationSeverityType.WARNING) // check if the call was successful
                {
                    shippingOptions = ParseAnswer(reply);
                }
                else
                {
                    Debug.LogError(new Exception(reply.Notifications[0].Message), false);
                }
            }
            catch (SoapException e)
            {
                Debug.LogError(e);
            }
            catch (Exception e)
            {
                Debug.LogError(e);
            }
            return shippingOptions;
        }
        /// <summary>
        ///  Gets available shipping options
        /// </summary>
        /// <param name="ShipmentPackage">Shipment package</param>
        /// <param name="Error">Error</param>
        /// <returns>Shipping options</returns>
        public ShippingOptionCollection GetShippingOptions(ShipmentPackage ShipmentPackage, ref string Error)
        {
            ShippingOptionCollection shippingOptions = new ShippingOptionCollection();

            if (ShipmentPackage == null)
            {
                throw new ArgumentNullException("ShipmentPackage");
            }
            if (ShipmentPackage.Items == null)
            {
                throw new NopException("No shipment items");
            }
            if (ShipmentPackage.ShippingAddress == null)
            {
                Error = "Shipping address is not set";
                return(shippingOptions);
            }
            if (ShipmentPackage.ShippingAddress.Country == null)
            {
                Error = "Shipping country is not set";
                return(shippingOptions);
            }

            MeasureWeight baseWeightIn = MeasureManager.BaseWeightIn;

            if (baseWeightIn.SystemKeyword != "lb")
            {
                throw new NopException("USPS shipping service. Base weight should be set to lb(s)");
            }

            MeasureDimension baseDimensionIn = MeasureManager.BaseDimensionIn;

            if (baseDimensionIn.SystemKeyword != "inches")
            {
                throw new NopException("USPS shipping service. Base dimension should be set to inch(es)");
            }



            RateRequest request = CreateRateRequest(ShipmentPackage);
            RateService service = new RateService(); // Initialize the service

            service.Url = SettingManager.GetSettingValue("ShippingRateComputationMethod.FedEx.URL");
            try
            {
                // This is the call to the web service passing in a RateRequest and returning a RateReply
                RateReply reply = service.getRates(request);                                                                                                                                          // Service call
                //
                if (reply.HighestSeverity == NotificationSeverityType.SUCCESS || reply.HighestSeverity == NotificationSeverityType.NOTE || reply.HighestSeverity == NotificationSeverityType.WARNING) // check if the call was successful
                {
                    if (reply != null && reply.RateReplyDetails != null)
                    {
                        shippingOptions = ParseResponse(reply);
                    }
                    else
                    {
                        Error = "Could not get reply from shipping server";
                    }
                }
                else
                {
                    Debug.WriteLine(reply.Notifications[0].Message);
                    Error = reply.Notifications[0].Message;
                }
            }
            catch (SoapException e)
            {
                Debug.WriteLine(e.Detail.InnerText);
                Error = e.Detail.InnerText;
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
                Error = e.Message;
            }



            if (String.IsNullOrEmpty(Error) && shippingOptions.Count == 0)
            {
                Error = "Shipping options could not be loaded";
            }
            return(shippingOptions);
        }