Example #1
0
 public Rate(RateDS.RateTableRow rate)
 {
     //Constructor
     try {
         if (rate != null)
         {
             if (!rate.IsOrgZipNull())
             {
                 this.mOrgZip = rate.OrgZip;
             }
             if (!rate.IsDestZipNull())
             {
                 this.mDestZip = rate.DestZip;
             }
             if (!rate.IsMinChargeNull())
             {
                 this.mMinCharge = rate.MinCharge;
             }
             if (!rate.IsRate1Null())
             {
                 this.mRate1 = rate.Rate1;
             }
             if (!rate.IsRate501Null())
             {
                 this.mRate501 = rate.Rate501;
             }
             if (!rate.IsRate1001Null())
             {
                 this.mRate1001 = rate.Rate1001;
             }
             if (!rate.IsRate2001Null())
             {
                 this.mRate2001 = rate.Rate2001;
             }
             if (!rate.IsRate5001Null())
             {
                 this.mRate5001 = rate.Rate5001;
             }
             if (!rate.IsRate10001Null())
             {
                 this.mRate10001 = rate.Rate10001;
             }
             if (!rate.IsRate20001Null())
             {
                 this.mRate20001 = rate.Rate20001;
             }
         }
     }
     catch (Exception ex) { throw new ApplicationException("Unexpected error while creating new Rate instance", ex); }
 }
Example #2
0
        public static RateDS CalculateRates(string tariff, string originZip, string classCode, double discount, int floorMin, string[] destinationZips)
        {
            //Calcualate rates
            RateDS rates = null;

            rates = new RateDS();
            _CzarLib.Clear();
            _CzarLib.tariff_name   = tariff.Substring(0, 8);
            _CzarLib.shipment_date = tariff.Substring(12, 2) + "/" + tariff.Substring(14, 2) + "/" + tariff.Substring(8, 4);
            _CzarLib.orgzip        = originZip;
            _CzarLib.set_cls(0, classCode);
            _CzarLib.set_wbdisc_in(0, discount); // min charge
            _CzarLib.set_wbdisc_in(1, discount); // < 500
            _CzarLib.set_wbdisc_in(2, discount); // > 500
            _CzarLib.set_wbdisc_in(3, discount); // > 1000
            _CzarLib.set_wbdisc_in(4, discount); // > 2000
            _CzarLib.set_wbdisc_in(5, discount); // > 5000
            _CzarLib.use_dscnts      = "Y";
            _CzarLib.discount_type   = "R";
            _CzarLib.single_shipment = "N";

            bool      isSuccess = false;
            ArrayList rateArray = new ArrayList(WEIGHT_RANGE_COUNT);

            for (int i = 0; i < destinationZips.Length; i++)
            {
                rateArray.Clear();
                for (int j = 0; j < WEIGHT_RANGE_COUNT; j++)
                {
                    //Rate the shipment now - we are rating one shipment at a time - multiple shipments give same rates
                    int weight = Convert.ToInt32(WEIGHT_RANGES[j].ToString());
                    _CzarLib.dstzip = destinationZips[i].ToString();
                    _CzarLib.set_wgt(0, Convert.ToInt32(weight.ToString()));
                    _CzarLib.RateShipment();
                    if (_CzarLib.error_status != 0)
                    {
                        throw new ApplicationException("Error occured when rating using destination zip " + destinationZips[i].ToString() + ". (" + _CzarLib.get_GetErrorString(_CzarLib.error_status) + ")");
                    }
                    else
                    {
                        isSuccess = true;
                    }
                    if (isSuccess)
                    {
                        rateArray.Add(_CzarLib.get_rte(0).ToString("C")); //format double to 2-digit number
                    }
                    else
                    {
                        break;
                    }
                }
                //Quit the whole thing if we encounter error with fixed properties
                //Check for error code 217 - Destination Tariff not found
                //continue with the next if it's Destination related error
                if (!isSuccess && _CzarLib.error_status != 217)
                {
                    break;
                }
                double minCharge = Convert.ToDouble(_CzarLib.min_charge.ToString("F"));
                if (minCharge < floorMin)
                {
                    minCharge = floorMin;                      //take lesser of min charge from rate ware or set floor min
                }
                //Add Rates to the grid
                RateDS.RateTableRow row = rates.RateTable.NewRateTableRow();
                row.OrgZip    = _CzarLib.orgzip;
                row.DestZip   = _CzarLib.dstzip.Substring(0, 3);
                row.MinCharge = minCharge.ToString("C");
                if (rateArray.Count > 0)
                {
                    row.Rate1     = rateArray[0].ToString();
                    row.Rate501   = rateArray[1].ToString();
                    row.Rate1001  = rateArray[2].ToString();
                    row.Rate2001  = rateArray[3].ToString();
                    row.Rate5001  = rateArray[4].ToString();
                    row.Rate10001 = rateArray[5].ToString();
                    row.Rate20001 = rateArray[6].ToString();
                }
                rates.RateTable.AddRateTableRow(row);
            }
            return(rates);
        }