public RateResponse GetRate(Package package)
        {
            try
            {
                string url = "?API=RateV2&XML=<RateV2Request USERID=\"{0}\"><Package ID=\"0\"><Service>{1}</Service><ZipOrigination>{2}</ZipOrigination><ZipDestination>{3}</ZipDestination><Pounds>{4}</Pounds><Ounces>{5}</Ounces><Container>{6}</Container><Size>{7}</Size></Package></RateV2Request>";

                int lb = package.WeightInOunces / 16;
                int oz = package.WeightInOunces % 16;
                string container = package.PackageType.ToString().Replace("_", " ");
                if (container == "None")
                    url = url.Replace("<Container>{6}</Container>", "");
                string fromZip = package.FromAddress.Zip;
                if (package.OriginZipcode != null && package.OriginZipcode.Length > 0)
                    fromZip = package.OriginZipcode;

                
                url = GetURL() + url;
                url = String.Format(url, _userid, package.ServiceType.ToString(), fromZip, package.ToAddress.Zip, lb.ToString(), oz.ToString(), container, package.PackageSize.ToString().Replace("_", " "));
                string xml = web.DownloadString(url);
                if (xml.Contains("<Error>"))
                {
                    int idx1 = xml.IndexOf("<Description>") + 13;
                    int idx2 = xml.IndexOf("</Description>");
                    int l = xml.Length;
                    string errDesc = xml.Substring(idx1, idx2 - idx1);
                    throw new USPSManagerException(errDesc);
                }

                return RateResponse.FromXml(xml);
            }
            catch (WebException ex)
            {
                throw new USPSManagerException(ex);
            }
        }
        private decimal GetLiveRate(string shipperCode, string tableType, string tableClassCode, string destZip, string orgZip, double weightInOz)
        {
            decimal returnRate = 0;
            switch (shipperCode)
            {
                case "USPS":
                    {
                        try
                        {
                            if (_reply == null)
                            {

                                USPSManager m = new USPSManager("065TOTAL8347", false);

                                Package pack = new Package();

                                pack.ServiceType = ServiceType.All;
                                pack.PackageSize = PackageSize.Regular;
                                pack.FromAddress.Zip = orgZip;
                                pack.ToAddress.Zip = destZip;
                                pack.WeightInOunces = Convert.ToInt32(weightInOz);
                                pack.Machinable = true;
                                _reply = new RateResponse();
                                _reply = m.GetRate(pack);

                            }

                            foreach (MAX.USPS.Postage postage in _reply.Postage)
                            {

                                if (postage.Class.ToString() == tableClassCode)
                                {
                                    decimal postageAmount = 0;
                                    postageAmount = postage.Amount;
                                    return postageAmount;
                                }

                            }
                        }
                        catch (Exception)
                        {
                            return 0;
                        }
                    }
                    break;
                case "FEDEX":
                    {
                        try
                        {
                            FedExRates.RateService.ServiceType myService = FedExRates.RateService.ServiceType.FEDEX_GROUND;

                            switch (tableType)
                            {
                                case "FEDEX_GROUND":
                                    {
                                        myService = FedExRates.RateService.ServiceType.FEDEX_GROUND;
                                        break;
                                    }
                                case "EUROPE_FIRST_INTERNATIONAL_PRIORITY":
                                    {
                                        myService = FedExRates.RateService.ServiceType.EUROPE_FIRST_INTERNATIONAL_PRIORITY;
                                        break;
                                    }
                                case "FEDEX_1_DAY_FREIGHT":
                                    {
                                        myService = FedExRates.RateService.ServiceType.FEDEX_1_DAY_FREIGHT;
                                        break;
                                    }
                                case "FEDEX_2_DAY":
                                    {
                                        myService = FedExRates.RateService.ServiceType.FEDEX_2_DAY;
                                        break;
                                    }
                                case "FEDEX_2_DAY_FREIGHT":
                                    {
                                        myService = FedExRates.RateService.ServiceType.FEDEX_2_DAY_FREIGHT;
                                        break;
                                    }
                                case "FEDEX_3_DAY_FREIGHT":
                                    {
                                        myService = FedExRates.RateService.ServiceType.FEDEX_3_DAY_FREIGHT;
                                        break;
                                    }
                                case "FEDEX_EXPRESS_SAVER":
                                    {
                                        myService = FedExRates.RateService.ServiceType.FEDEX_EXPRESS_SAVER;
                                        break;
                                    }
                                case "FIRST_OVERNIGHT":
                                    {
                                        myService = FedExRates.RateService.ServiceType.FIRST_OVERNIGHT;
                                        break;
                                    }
                                case "GROUND_HOME_DELIVERY":
                                    {
                                        myService = FedExRates.RateService.ServiceType.GROUND_HOME_DELIVERY;
                                        break;
                                    }
                                case "INTERNATIONAL_ECONOMY":
                                    {
                                        myService = FedExRates.RateService.ServiceType.INTERNATIONAL_ECONOMY;
                                        break;
                                    }
                                case "INTERNATIONAL_ECONOMY_FREIGHT":
                                    {
                                        myService = FedExRates.RateService.ServiceType.INTERNATIONAL_ECONOMY_FREIGHT;
                                        break;
                                    }
                                case "INTERNATIONAL_FIRST":
                                    {
                                        myService = FedExRates.RateService.ServiceType.INTERNATIONAL_FIRST;
                                        break;
                                    }
                                case "INTERNATIONAL_PRIORITY":
                                    {
                                        myService = FedExRates.RateService.ServiceType.INTERNATIONAL_PRIORITY;
                                        break;

                                    }
                                case "INTERNATIONAL_PRIORITY_FREIGHT":
                                    {
                                        myService = FedExRates.RateService.ServiceType.INTERNATIONAL_PRIORITY_FREIGHT;
                                        break;
                                    }
                                case "PRIORITY_OVERNIGHT":
                                    {
                                        myService = FedExRates.RateService.ServiceType.PRIORITY_OVERNIGHT;
                                        break;
                                    }
                                case "STANDARD_OVERNIGHT":
                                    {
                                        myService = FedExRates.RateService.ServiceType.STANDARD_OVERNIGHT;
                                        break;
                                    }
                                default:
                                    break;

                            }
                            IWEB.FedEx.Rate myRate = new IWEB.FedEx.Rate();
                            myRate.ServiceType = myService;
                            myRate.DestinationCountryCode = "US";
                            myRate.DestinationZip = destZip;
                            myRate.OriginCountryCode = "US";
                            myRate.OriginZip = orgZip;
                            decimal dweightInOz = Convert.ToDecimal(weightInOz);
                            myRate.PackageWeightInOunces = dweightInOz;

                            decimal rate = myRate.GetRate();
                            if (rate != 0)
                            {
                                return rate;
                            }
                            else
                            {
                                return 0;
                            }
                        }
                        catch (Exception)
                        {
                            return 0;
                        }
                    }
                    break;
                case "UPS":
                    {

                    }
                    break;
                case "DHL":
                    {

                    }
                    break;
                default:
                    //there wasent something we know about, return null values
                    break;
            }

            return returnRate;
        }
 /// <summary>
 /// Fills a package's ShippingLabel with a Byte{} containing the Image for the label
 /// </summary>
 /// <param name="package">Package with From and To addresses provided</param>
 /// <returns>The same package with the ShippingLabel</returns>
 public Package GetSignatureConfirmationLabel(Package package)
 {
     string url = "?API=SignatureConfirmationV3&XML=<SignatureConfirmationV3.0Request USERID=\"{0}\"><Option>{1}</Option><ImageParameters></ImageParameters><FromName>{2}</FromName><FromFirm>{3}</FromFirm><FromAddress1>{4}</FromAddress1><FromAddress2>{5}</FromAddress2><FromCity>{6}</FromCity><FromState>{7}</FromState><FromZip5>{8}</FromZip5><FromZip4>{9}</FromZip4><ToName>{10}</ToName><ToFirm>{11}</ToFirm><ToAddress1>{12}</ToAddress1><ToAddress2>{13}</ToAddress2><ToCity>{14}</ToCity><ToState>{15}</ToState><ToZip5>{16}</ToZip5><ToZip4>{17}</ToZip4><WeightInOunces>{18}</WeightInOunces><ServiceType>{19}</ServiceType><POZipCode>{20}</POZipCode><ImageType>{21}</ImageType><LabelDate>{22}</LabelDate><CustomerRefNo>{23}</CustomerRefNo><AddressServiceRequested>{24}</AddressServiceRequested></SignatureConfirmationV3.0Request>";
     url = GetURL() + url;
     url = String.Format(url, this._userid, (int)package.LabelType, package.FromAddress.Contact, package.FromAddress.FirmName, package.FromAddress.Address1, package.FromAddress.Address2, package.FromAddress.City, package.FromAddress.State, package.FromAddress.Zip, package.FromAddress.ZipPlus4, package.ToAddress.Contact, package.ToAddress.FirmName, package.ToAddress.Address1, package.ToAddress.Address2, package.ToAddress.City, package.ToAddress.State, package.ToAddress.Zip, package.ToAddress.ZipPlus4, package.WeightInOunces.ToString(), package.ServiceType.ToString().Replace("_", " "), package.OriginZipcode, package.LabelImageType.ToString(), package.ShipDate.ToShortDateString(), package.ReferenceNumber, package.AddressServiceRequested.ToString(), package.FromAddress.Contact, package.FromAddress.ContactEmail, package.ToAddress.Contact, package.ToAddress.ContactEmail);
     string xml = web.DownloadString(url);
     if (xml.Contains("<Error>"))
     {
         int idx1 = xml.IndexOf("<Description>") + 13;
         int idx2 = xml.IndexOf("</Description>");
         int l = xml.Length;
         string errDesc = xml.Substring(idx1, idx2 - idx1);
         throw new USPSManagerException(errDesc);
     }
     int i1 = xml.IndexOf("<SignatureConfirmationLabel>") + 28;
     int i2 = xml.IndexOf("</DeliveryConfirmationLabel>");
     package.ShippingLabel = StringToUTF8ByteArray(xml.Substring(i1, i2 - i1));
     return package;
 }