public virtual AvailabilityForecast getAvailabilityForecast(ProspectiveLineItem lineItem, AvailabilityForecastOptions forecastOptions) {
   object[] results = this.Invoke("getAvailabilityForecast", new object[] { lineItem, forecastOptions });
   return ((AvailabilityForecast) (results[0]));
 }
    /// <summary>
    /// Run the code example.
    /// </summary>
    /// <param name="user">The DFP user object running the code example.</param>
    public override void Run(DfpUser user) {
      // Get the ForecastService.
      ForecastService forecastService =
          (ForecastService)user.GetService(DfpService.v201505.ForecastService);

      // Set the placement that the prospective line item will target.
      long[] targetPlacementIds = new long[] {long.Parse(_T("INSERT_PLACEMENT_ID_HERE"))};

      // Create prospective line item.
      LineItem lineItem = new LineItem();

      lineItem.targeting = new Targeting();
      lineItem.targeting.inventoryTargeting = new InventoryTargeting();
      lineItem.targeting.inventoryTargeting.targetedPlacementIds = targetPlacementIds;

      Size size = new Size();
      size.width = 300;
      size.height = 250;

      // Create the creative placeholder.
      CreativePlaceholder creativePlaceholder = new CreativePlaceholder();
      creativePlaceholder.size = size;

      lineItem.creativePlaceholders = new CreativePlaceholder[] {creativePlaceholder};

      lineItem.lineItemType = LineItemType.SPONSORSHIP;
      lineItem.startDateTimeType = StartDateTimeType.IMMEDIATELY;

      // Set the line item to run for one month.
      lineItem.endDateTime =
          DateTimeUtilities.FromDateTime(System.DateTime.Now.AddMonths(1), "America/New_York");

      // Set the cost type to match the unit type.
      lineItem.costType = CostType.CPM;
      Goal goal = new Goal();
      goal.goalType = GoalType.DAILY;
      goal.unitType = UnitType.IMPRESSIONS;
      goal.units = 50L;
      lineItem.primaryGoal = goal;

      try {
        // Get availability forecast.
        AvailabilityForecastOptions options = new AvailabilityForecastOptions();
        options.includeContendingLineItems = true;
        options.includeTargetingCriteriaBreakdown = true;
        ProspectiveLineItem prospectiveLineItem = new ProspectiveLineItem();
        prospectiveLineItem.lineItem = lineItem;
        AvailabilityForecast forecast =
            forecastService.getAvailabilityForecast(prospectiveLineItem, options);

        // Display results.
        long matched = forecast.matchedUnits;
        double availablePercent = (double) (forecast.availableUnits / (matched * 1.0)) * 100;
        String unitType = forecast.unitType.ToString().ToLower();
        Console.WriteLine("{0} {1} matched.\n{2}%  available.", matched, unitType,
            availablePercent, unitType);

        if (forecast.possibleUnitsSpecified) {
          double possiblePercent = (double) (forecast.possibleUnits / (matched * 1.0)) * 100;
          Console.WriteLine("{0}% {1} possible.\n", possiblePercent, unitType);
        }
        Console.WriteLine("{0} contending line items.", (forecast.contendingLineItems != null) ?
            forecast.contendingLineItems.Length : 0);
      } catch (Exception e) {
        Console.WriteLine("Failed to get forecast. Exception says \"{0}\"", e.Message);
      }
    }
    public void TestGetAvailabilityForecast() {
      TestUtils utils = new TestUtils();

      LineItem lineItem = new LineItem();
      lineItem.name = string.Format("Line item #{0}", utils.GetTimeStamp());

      lineItem.orderId = orderId;

      lineItem.targeting = new Targeting();
      lineItem.targeting.inventoryTargeting = new InventoryTargeting();
      lineItem.targeting.inventoryTargeting.targetedPlacementIds = new long[] {placementId};

      Size size1 = new Size();
      size1.width = 300;
      size1.height = 250;

      Size size2 = new Size();
      size2.width = 120;
      size2.height = 600;

      // Create the creative placeholders.
      CreativePlaceholder creativePlaceholder1 = new CreativePlaceholder();
      creativePlaceholder1.size = size1;

      CreativePlaceholder creativePlaceholder2 = new CreativePlaceholder();
      creativePlaceholder1.size = size2;

      lineItem.creativePlaceholders =
          new CreativePlaceholder[] {creativePlaceholder1, creativePlaceholder2};

      lineItem.lineItemType = LineItemType.STANDARD;

      // Set start date time and end date time.
      lineItem.startDateTime =
          DateTimeUtilities.FromDateTime(System.DateTime.Today.AddDays(1), "America/New_York");
      lineItem.endDateTime =
          DateTimeUtilities.FromDateTime(System.DateTime.Today.AddMonths(1), "America/New_York");

      lineItem.costType = CostType.CPM;
      lineItem.costPerUnit = new Money();
      lineItem.costPerUnit.currencyCode = "USD";
      lineItem.costPerUnit.microAmount = 2000000;

      lineItem.creativeRotationType = CreativeRotationType.EVEN;
      lineItem.discountType = LineItemDiscountType.PERCENTAGE;

      Goal goal = new Goal();
      goal.units = 500000;
      goal.unitType = UnitType.IMPRESSIONS;
      lineItem.primaryGoal = goal;

      ProspectiveLineItem prospectiveLineItem = new ProspectiveLineItem();
      prospectiveLineItem.lineItem = lineItem;

      AvailabilityForecast forecast = null;
      Assert.DoesNotThrow(delegate() {
        forecast = forecastService.getAvailabilityForecast(prospectiveLineItem,
            new AvailabilityForecastOptions());
      });
      Assert.NotNull(forecast);
      Assert.AreEqual(forecast.orderId, orderId);
      Assert.AreEqual(forecast.unitType, lineItem.primaryGoal.unitType);
    }