Example #1
0
        private void GetYRCInfo_API(ref bool isDurachem, ref string[] weight, ref string[] fclass,
                                    ref string[] nmfc, ref string[] pieces, ref int numLineItems, ref bool dimsProvided,
                                    ref string[] cube, ref string[] density, ref StringBuilder sbAccessorials, int AccOptionCount, ref string[] length,
                                    ref string[] width, ref string[] height)
        {
            //DB.Log("YRC Live", "GetYRCInfo");

            YRC_Res = new YRC_Result();
            try
            {
                #region Variables

                //DateTime today = DateTime.Today;
                DateTime today     = quoteData.puDate;
                string   day       = today.Day.ToString();
                string   month     = today.Month.ToString();
                string   year      = today.Year.ToString();
                string   dayOfWeek = today.DayOfWeek.ToString();
                dayOfWeek = dayOfWeek.Remove(3);
                if (day.Length == 1)
                {
                    day = "0" + day;
                }
                if (month.Length == 1)
                {
                    month = "0" + month;
                }

                string doc = "";
                string url, referrer, contentType, accept, method;

                #endregion

                #region Country

                string origCountry = "USA";
                string destCountry = "USA";
                if (HelperFuncs.GetCountryByZip(quoteData.origZip, true, quoteData.origZip, quoteData.destZip).Equals("CANADA"))
                {
                    origCountry = "CAN";
                }
                if (HelperFuncs.GetCountryByZip(quoteData.destZip, false, quoteData.origZip, quoteData.destZip).Equals("CANADA"))
                {
                    destCountry = "CAN";
                }

                #endregion

                #region 10 units limit

                if (fclass.Length > 10)
                {
                    throw new Exception("YRC Freight: Shipments of up to 10 units are handled, you have entered " + fclass.Length.ToString() + " units.");
                }

                #endregion

                #region Items

                StringBuilder items = new StringBuilder();

                string itemNum = string.Empty;

                for (int i = 0; i < fclass.Length; i++)
                {
                    itemNum = (i + 1).ToString();
                    items.Append(string.Concat("&LineItemWeight", itemNum, "=", weight[i]));

                    if (fclass[i].Equals(string.Empty))
                    {
                        // Use NMFC instead of class
                        string[] forSplit = nmfc[i].Split('-');
                        if (forSplit.Length.Equals(2))
                        {
                            items.Append(string.Concat("&LineItemNmfcPrefix", itemNum, "=", forSplit[0], "&LineItemNmfcSuffix", itemNum, "=0", forSplit[1]));
                        }
                        else
                        {
                            items.Append(string.Concat("&LineItemNmfcPrefix", itemNum, "=", nmfc[i], "&LineItemNmfcSuffix", itemNum, "="));
                        }
                    }
                    else
                    {
                        items.Append(string.Concat("&LineItemNmfcClass", itemNum, "="));
                        items.Append(fclass[i]);
                    }

                    items.Append(string.Concat("&LineItemCount", itemNum, "=", pieces[i]));

                    if (dimsProvided.Equals(true))
                    {
                        items.Append(
                            string.Concat(
                                "&LineItemPackageLength", itemNum, "=", length[i],
                                "&LineItemPackageWidth", itemNum, "=", width[i],
                                "&LineItemPackageHeight", itemNum, "=", height[i])
                            );
                    }
                }

                #endregion

                #region Make http requests

                referrer = "";
                url      = string.Concat("http://my.yrc.com/myyrc-api/national/servlet?CONTROLLER=com.rdwy.ec.rexcommon.proxy.http.controller.ProxyApiController&redir=/tfq561",
                                         "&LOGIN_USERID=", acctInfo.username, "&LOGIN_PASSWORD="******"&BusId=", acctInfo.acctNum, "&BusRole=Third%20Party&PaymentTerms=Prepaid",
                                         "&OrigCityName=", quoteData.origCity.Replace(" ", "%20"), "&OrigStateCode=", quoteData.origState, "&OrigZipCode=", quoteData.origZip, "&OrigNationCode=", origCountry,
                                         "&DestCityName=", quoteData.destCity.Replace(" ", "%20"), "&DestStateCode=", quoteData.destState, "&DestZipCode=", quoteData.destZip, "&DestNationCode=", destCountry,
                                         "&ServiceClass=STD&PickupDate=", year, month, day, "&TypeQuery=QUOTE",
                                         items, "&LineItemCount=", fclass.Length,

                                         sbAccessorials, "&AccOptionCount=", AccOptionCount);

                //"&AccOption1=HOMD&AccOptionCount=1");
                contentType = "";
                method      = "GET";
                accept      = "*/*";
                doc         = (string)HelperFuncs.generic_http_request("string", null, url, referrer, contentType, accept, method, "", false);

                //DB.Log("YRC Live request", url);
                //DB.Log("YRC_Live response", doc);


                #endregion

                #region Get regular rates

                //string tmp = doc;
                bool isIntraCanada = false;
                if (origCountry == "CAN" && destCountry == "CAN")
                {
                    if (!quoteData.username.ToLower().Equals("durachem"))
                    {
                        throw new Exception("Intra Canada");  // Intra Canada enabled only for durachem for now
                    }
                    isIntraCanada = true;
                }

                #region Get cost and transit days from the result

                string[] tokens = new string[3];
                tokens[0] = "<TotalCharges>";
                tokens[1] = ">";
                tokens[2] = "<";

                string costStr = HelperFuncs.scrapeFromPage(tokens, doc);

                //DB.Log("YRC_Live costStr", costStr);

                int costInt   = -1;
                int costCents = 0;

                if (int.TryParse(costStr, out int testInt))
                {
                    costInt   = testInt / 100;
                    costCents = testInt % 100;

                    //DB.Log("YRC_Live costInt costCents", costInt + " " + costCents);
                }

                if (double.TryParse(string.Concat(costInt, ".", costCents.ToString().PadLeft(2, '0')), out double costDouble))
                {
                    YRC_Res.standardLTL = costDouble;
                    //DB.Log("YRC_Live costDouble", costDouble.ToString());
                }

                YRC_Res.days = 5;
                tokens[0]    = "<StandardDays>";

                int.TryParse(HelperFuncs.scrapeFromPage(tokens, doc), out YRC_Res.days);

                #endregion

                #endregion
            }

            catch (Exception e)
            {
                #region Exception code

                DB.Log("YRC", e.ToString());

                YRC_Res.standardLTL = -1;

                #endregion
            }
        }