示例#1
0
        static void Main(string[] args)
        {
            // You will need a license #, userid and password to utilize the UPS provider.
            string upsLicenseNumber = "";
            string upsUserId        = "";
            string upsPassword      = "";

            // You will need a userid, password, account # and shipping key to utilize the Airborne provider.
            string airborneUserId        = "";
            string airbornePassword      = "";
            string airborneAccountNumber = "";
            string airborneShippingKey   = "";

            // Setup package and destination/origin addresses
            dotNETShipping.Package package     = new dotNETShipping.Package(12, 12, 16, 10, 1000);
            dotNETShipping.Address origin      = new dotNETShipping.Address("Tampa", "FL", "33634", "US");
            dotNETShipping.Address destination = new dotNETShipping.Address("Newark", "DE", "19714", "US");

            // Create RateManager
            dotNETShipping.RateManager rateManager = new dotNETShipping.RateManager(true);

            // Add desired dotNETShippingProviders
            rateManager.AddProvider(new dotNETShipping.ShippingProviders.UPSProvider(upsLicenseNumber, upsUserId, upsPassword));

            // You will need an account # and meter # to utilize the FedEx provider.
            string fedexAccountNumber = "";
            string fedexMeterNumber   = "";

            // We don't want discounts from FedEx, so we need to create an object reference and set the "ApplyDiscounts" property.
            dotNETShipping.ShippingProviders.FedExProvider fedEx = new dotNETShipping.ShippingProviders.FedExProvider(fedexAccountNumber, fedexMeterNumber);
            fedEx.ApplyDiscounts = false;
            rateManager.AddProvider(fedEx);

            // We want FedEx ground services, so we have to create a second instance and set the "Services" property.
            dotNETShipping.ShippingProviders.FedExProvider fedExGround = new dotNETShipping.ShippingProviders.FedExProvider(fedexAccountNumber, fedexMeterNumber);
            fedExGround.ApplyDiscounts = false;
            fedExGround.Services       = ShippingProviders.FedExProvider.AvailableServices.HomeDelivery | ShippingProviders.FedExProvider.AvailableServices.Ground;
            rateManager.AddProvider(fedExGround);

            // We don't want all services from Airborne, so we need to create an object reference and set the "Services" property.
            dotNETShipping.ShippingProviders.AirborneProvider airborne = new dotNETShipping.ShippingProviders.AirborneProvider(airborneUserId, airbornePassword, airborneAccountNumber, airborneShippingKey);
            airborne.Services = dotNETShipping.ShippingProviders.AirborneProvider.AvailableServices.All ^ dotNETShipping.ShippingProviders.AirborneProvider.AvailableServices.Ground;
            rateManager.AddProvider(airborne);

            // Call GetRates()
            dotNETShipping.Shipment shipment = rateManager.GetRates(origin, destination, package);

            // Iterate through the rates returned
            foreach (dotNETShipping.Rate rate in shipment.Rates)
            {
                System.Diagnostics.Debug.WriteLine(rate);
            }
        }
示例#2
0
        static void Main(string[] args)
        {
            // You will need a license #, userid and password to utilize the UPS provider.
            string upsLicenseNumber = "";
            string upsUserId = "";
            string upsPassword = "";

            // You will need a userid, password, account # and shipping key to utilize the Airborne provider.
            string airborneUserId = "";
            string airbornePassword = "";
            string airborneAccountNumber = "";
            string airborneShippingKey = "";

            // Setup package and destination/origin addresses
            dotNETShipping.Package package = new dotNETShipping.Package(12, 12, 16, 10, 1000);
            dotNETShipping.Address origin = new dotNETShipping.Address("Tampa", "FL", "33634", "US");
            dotNETShipping.Address destination = new dotNETShipping.Address("Newark", "DE", "19714", "US");

            // Create RateManager
            dotNETShipping.RateManager rateManager = new dotNETShipping.RateManager(true);

            // Add desired dotNETShippingProviders
            rateManager.AddProvider(new dotNETShipping.ShippingProviders.UPSProvider(upsLicenseNumber, upsUserId, upsPassword));

            // You will need an account # and meter # to utilize the FedEx provider.
            string fedexAccountNumber = "";
            string fedexMeterNumber = "";
            // We don't want discounts from FedEx, so we need to create an object reference and set the "ApplyDiscounts" property.
            dotNETShipping.ShippingProviders.FedExProvider fedEx = new dotNETShipping.ShippingProviders.FedExProvider(fedexAccountNumber, fedexMeterNumber);
            fedEx.ApplyDiscounts = false;
            rateManager.AddProvider(fedEx);

            // We want FedEx ground services, so we have to create a second instance and set the "Services" property.
            dotNETShipping.ShippingProviders.FedExProvider fedExGround = new dotNETShipping.ShippingProviders.FedExProvider(fedexAccountNumber, fedexMeterNumber);
            fedExGround.ApplyDiscounts = false;
            fedExGround.Services = ShippingProviders.FedExProvider.AvailableServices.HomeDelivery | ShippingProviders.FedExProvider.AvailableServices.Ground;
            rateManager.AddProvider(fedExGround);

            // We don't want all services from Airborne, so we need to create an object reference and set the "Services" property.
            dotNETShipping.ShippingProviders.AirborneProvider airborne = new dotNETShipping.ShippingProviders.AirborneProvider(airborneUserId, airbornePassword, airborneAccountNumber, airborneShippingKey);
            airborne.Services = dotNETShipping.ShippingProviders.AirborneProvider.AvailableServices.All ^ dotNETShipping.ShippingProviders.AirborneProvider.AvailableServices.Ground;
            rateManager.AddProvider(airborne);

            // Call GetRates()
            dotNETShipping.Shipment shipment = rateManager.GetRates(origin, destination, package);

            // Iterate through the rates returned
            foreach (dotNETShipping.Rate rate in shipment.Rates)
                System.Diagnostics.Debug.WriteLine(rate);
        }
示例#3
0
        /// <summary>
        /// Subscribes an account number and returns a meter number.
        /// </summary>
        /// <param name="accountNumber">The FedEx account number to be subscribed.</param>
        /// <param name="contact">The contact information of the person subscribing.</param>
        /// <param name="address">The address information of the person subscribing.</param>
        /// <returns>A meter number.</returns>
        /// <remarks>
        /// This method only needs to be called once for a given account number.<br/>
        /// The returned meter number is then used when requesting rates or tracking information from FedEx.
        /// </remarks>
        public static string Subscribe(string accountNumber, Contact contact, dotNETShipping.Address address)
        {
            Encoding      utf8   = new UTF8Encoding(false);
            XmlTextWriter writer = new XmlTextWriter(new MemoryStream(1000), utf8);

            writer.WriteStartDocument();
            writer.WriteStartElement("FDXSubscriptionRequest");
            writer.WriteAttributeString("xmlns:api", "http://www.fedex.com/fsmapi");
            writer.WriteAttributeString("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
            writer.WriteAttributeString("xsi:noNamespaceSchemaLocation", "FDXSubscriptionRequest.xsd");
            writer.WriteStartElement("RequestHeader");
            writer.WriteElementString("CustomerTransactionIdentifier", "SubscriptionRequest");
            writer.WriteElementString("AccountNumber", accountNumber);
            writer.WriteEndElement();
            writer.WriteStartElement("Contact");
            writer.WriteElementString("PersonName", contact.PersonName);
            writer.WriteElementString("CompanyName", contact.CompanyName);
            writer.WriteElementString("Department", contact.Department);
            writer.WriteElementString("PhoneNumber", contact.PhoneNumber.Replace("-", "").Replace("(", "").Replace(")", ""));
            if (contact.PagerNumber.Length > 0)
            {
                writer.WriteElementString("PagerNumber", contact.PagerNumber.Replace("-", "").Replace("(", "").Replace(")", ""));
            }
            if (contact.FaxNumber.Length > 0)
            {
                writer.WriteElementString("FaxNumber", contact.FaxNumber.Replace("-", "").Replace("(", "").Replace(")", ""));
            }
            writer.WriteElementString("E-MailAddress", contact.EmailAddress);
            writer.WriteEndElement();
            writer.WriteStartElement("Address");
            writer.WriteElementString("Line1", address.Line1);
            writer.WriteElementString("Line2", address.Line2);
            writer.WriteElementString("City", address.City);
            writer.WriteElementString("StateOrProvinceCode", address.State);
            writer.WriteElementString("PostalCode", address.PostalCode);
            writer.WriteElementString("CountryCode", address.CountryCode);
            writer.WriteEndElement();
            writer.WriteEndDocument();

            writer.Flush();
            byte[] buffer = new byte[writer.BaseStream.Length];
            writer.BaseStream.Position = 0;
            writer.BaseStream.Read(buffer, 0, buffer.Length);
            string message = System.Text.Encoding.UTF8.GetString(buffer);

            writer.Close();
            System.Diagnostics.Debug.WriteLine(message);

            string temp        = "";
            string meterNumber = "";

            try
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(FedExProvider.url);
                request.Method      = "POST";
                request.ContentType = "application/x-www-form-urlencoded";
                request.Timeout     = 10 * 1000;
                byte[] bytes = System.Text.Encoding.ASCII.GetBytes(message);
                request.ContentLength = bytes.Length;
                Stream stream = request.GetRequestStream();
                stream.Write(bytes, 0, bytes.Length);
                stream.Close();
                System.Diagnostics.Debug.WriteLine("Request Sent!", "FedEx");
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                temp = new StreamReader(response.GetResponseStream()).ReadToEnd();
                response.Close();
                System.Diagnostics.Debug.WriteLine(temp);

                XmlDocument xDoc = new XmlDocument();
                xDoc.LoadXml(temp);
                XmlNode nodeMeterNumber = xDoc.SelectSingleNode("/FDXSubscriptionReply/MeterNumber");
                if (nodeMeterNumber != null)
                {
                    meterNumber = nodeMeterNumber.InnerText;
                }
            }
            catch (System.Net.WebException ex)
            {
                System.Diagnostics.Debug.WriteLine(ex);
            }

            return(meterNumber);
        }