Example #1
0
 public void Combine(DeliveryOptionCollection options)
 {
     foreach (var option in options)
     {
         this.Add(option);
     }
 }
Example #2
0
        private IEnumerable <DeliveryOption> UpsParseRates(string response)
        {
            var optionCollection = new DeliveryOptionCollection();

            var sr = new StringReader(response);
            var tr = new XmlTextReader(sr);

            try
            {
                while (tr.Read())
                {
                    if ((tr.Name == "Error") && (tr.NodeType == XmlNodeType.Element))
                    {
                        string errorText = "";
                        while (tr.Read())
                        {
                            if ((tr.Name == "ErrorCode") && (tr.NodeType == XmlNodeType.Element))
                            {
                                errorText += "UPS Rating Error, Error Code: " + tr.ReadString() + ", ";
                            }
                            if ((tr.Name == "ErrorDescription") && (tr.NodeType == XmlNodeType.Element))
                            {
                                errorText += "Error Desc: " + tr.ReadString();
                            }
                        }
                        throw new ProviderException("UPS Error returned: " + errorText);
                    }
                    if ((tr.Name == "RatedShipment") && (tr.NodeType == XmlNodeType.Element))
                    {
                        string serviceCode   = "";
                        string monetaryValue = "";
                        while (tr.Read())
                        {
                            if ((tr.Name == "Service") && (tr.NodeType == XmlNodeType.Element))
                            {
                                while (tr.Read())
                                {
                                    if ((tr.Name == "Code") && (tr.NodeType == XmlNodeType.Element))
                                    {
                                        serviceCode = tr.ReadString();
                                        tr.ReadEndElement();
                                    }
                                    if ((tr.Name == "Service") && (tr.NodeType == XmlNodeType.EndElement))
                                    {
                                        break;
                                    }
                                }
                            }
                            if (((tr.Name == "RatedShipment") && (tr.NodeType == XmlNodeType.EndElement)) || ((tr.Name == "RatedPackage") && (tr.NodeType == XmlNodeType.Element)))
                            {
                                break;
                            }
                            if ((tr.Name == "TotalCharges") && (tr.NodeType == XmlNodeType.Element))
                            {
                                while (tr.Read())
                                {
                                    if ((tr.Name == "MonetaryValue") && (tr.NodeType == XmlNodeType.Element))
                                    {
                                        monetaryValue = tr.ReadString();
                                        tr.ReadEndElement();
                                    }
                                    if ((tr.Name == "TotalCharges") && (tr.NodeType == XmlNodeType.EndElement))
                                    {
                                        break;
                                    }
                                }
                            }
                        }

                        var service = GetServiceName(serviceCode);
                        var rate    = Convert.ToDecimal(monetaryValue);

                        // tack on additional handling charge for each bag
                        if (!String.IsNullOrEmpty(_settings.UpsAdditionalHandlingCharge))
                        {
                            decimal additionalHandling = Convert.ToDecimal(_settings.UpsAdditionalHandlingCharge);
                        }

                        //Weed out unwanted or unkown service rates
                        if (service.ToUpper() != "UNKNOWN" && IncludedService(serviceCode))
                        {
                            var option = new DeliveryOption {
                                Rate = rate, Service = service
                            };
                            optionCollection.Add(option);
                        }
                    }
                }
                sr.Dispose();
                return(optionCollection);
            }
            catch (SystemException ex)
            {
                throw new SystemException(ex.Message);
            }
            finally
            {
                sr.Close();
                tr.Close();
            }
        }