Runs the example.

@param adManagerServices the services factory.
@param session the session.
@throws ApiException if the API request failed with one or more service errors.
@throws RemoteException if the API request failed due to other errors.
172829
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session)
      throws RemoteException {
    // Get the ReconciliationReportService.
    ReconciliationReportServiceInterface reconciliationReportService =
        adManagerServices.get(session, ReconciliationReportServiceInterface.class);

    // Create a statement to select all reconciliation reports.
    StatementBuilder statementBuilder = new StatementBuilder()
        .orderBy("id ASC")
        .limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);

    // Default for total result set size.
    int totalResultSetSize = 0;

    do {
      // Get reconciliation reports by statement.
      ReconciliationReportPage page =
          reconciliationReportService.getReconciliationReportsByStatement(
              statementBuilder.toStatement());

      if (page.getResults() != null) {
        totalResultSetSize = page.getTotalResultSetSize();
        int i = page.getStartIndex();
        for (ReconciliationReport reconciliationReport : page.getResults()) {
          System.out.printf(
              "%d) Reconciliation report with ID %d for month %d/%d was found.%n",
              i++,
              reconciliationReport.getId(),
              reconciliationReport.getStartDate().getMonth(),
              reconciliationReport.getStartDate().getYear());
        }
      }

      statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);

    System.out.printf("Number of results found: %d%n", totalResultSetSize);
  }
768922
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session)
      throws RemoteException {
    // Get the AdjustmentService.
    AdjustmentServiceInterface adjustmentService =
        adManagerServices.get(session, AdjustmentServiceInterface.class);

    // Create a statement to get all forecast adjustments.
    StatementBuilder statementBuilder =
        new StatementBuilder().orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);

    // Default for total result set size.
    int totalResultSetSize = 0;

    do {
      // Get forecast adjustments by statement.
      TrafficForecastAdjustmentPage page =
          adjustmentService.getTrafficAdjustmentsByStatement(statementBuilder.toStatement());

      if (page.getResults() != null) {
        totalResultSetSize = page.getTotalResultSetSize();
        int i = page.getStartIndex();
        for (TrafficForecastAdjustment adjustment : page.getResults()) {
          System.out.printf(
              "%d) Forecast adjustment with ID %d containing %d adjustment segments was found.%n",
              i++,
              adjustment.getId(),
              adjustment.getForecastAdjustmentSegments() != null
                  ? adjustment.getForecastAdjustmentSegments().length
                  : 0);
        }
      }

      statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);

    System.out.printf("Number of results found: %d%n", totalResultSetSize);
  }
389207
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session)
      throws RemoteException {
    // Get the CustomTargetingService.
    CustomTargetingServiceInterface customTargetingService =
        adManagerServices.get(session, CustomTargetingServiceInterface.class);

    // Create predefined key.
    CustomTargetingKey genderKey = new CustomTargetingKey();
    genderKey.setDisplayName("gender");
    genderKey.setName("g" + new Random().nextInt(1000));
    genderKey.setType(CustomTargetingKeyType.PREDEFINED);

    // Create predefined key that may be used for content targeting.
    CustomTargetingKey genreKey = new CustomTargetingKey();
    genreKey.setDisplayName("genre");
    genreKey.setName("genre" + new Random().nextInt(1000));
    genreKey.setType(CustomTargetingKeyType.PREDEFINED);

    // Create free-form key.
    CustomTargetingKey carModelKey = new CustomTargetingKey();
    carModelKey.setDisplayName("car model");
    carModelKey.setName("c" + new Random().nextInt(1000));
    carModelKey.setType(CustomTargetingKeyType.FREEFORM);

    // Create the custom targeting keys on the server.
    CustomTargetingKey[] customTargetingKeys = customTargetingService.createCustomTargetingKeys(
        new CustomTargetingKey[] {genderKey, genreKey, carModelKey});

    for (CustomTargetingKey createdCustomTargetingKey : customTargetingKeys) {
      System.out.printf("A custom targeting key with ID %d, name '%s', and display name "
          + "'%s' was created.%n", createdCustomTargetingKey.getId(),
          createdCustomTargetingKey.getName(), createdCustomTargetingKey.getDisplayName());
    }

    // Set the created custom targeting keys.
    genderKey = customTargetingKeys[0];
    genreKey = customTargetingKeys[1];
    carModelKey = customTargetingKeys[2];

    // Create custom targeting value for the predefined gender key.
    CustomTargetingValue genderMaleValue = new CustomTargetingValue();
    genderMaleValue.setCustomTargetingKeyId(genderKey.getId());
    genderMaleValue.setDisplayName("male");
    // Name is set to 1 so that the actual name can be hidden from website
    // users.
    genderMaleValue.setName("1");
    genderMaleValue.setMatchType(CustomTargetingValueMatchType.EXACT);

    CustomTargetingValue genderFemaleValue = new CustomTargetingValue();
    genderFemaleValue.setCustomTargetingKeyId(genderKey.getId());
    genderFemaleValue.setDisplayName("female");
    // Name is set to 2 so that the actual name can be hidden from website
    // users.
    genderFemaleValue.setName("2");
    genderFemaleValue.setMatchType(CustomTargetingValueMatchType.EXACT);

    // Create custom targeting value for the predefined genre key.
    CustomTargetingValue genreComedyValue = new CustomTargetingValue();
    genreComedyValue.setCustomTargetingKeyId(genreKey.getId());
    genreComedyValue.setDisplayName("comedy");
    genreComedyValue.setName("comedy");
    genreComedyValue.setMatchType(CustomTargetingValueMatchType.EXACT);

    CustomTargetingValue genreDramaValue = new CustomTargetingValue();
    genreDramaValue.setCustomTargetingKeyId(genreKey.getId());
    genreDramaValue.setDisplayName("drama");
    genreDramaValue.setName("drama");
    genreDramaValue.setMatchType(CustomTargetingValueMatchType.EXACT);

    // Create custom targeting value for the free-form car model key. These are
    // values that would be suggested in the UI or can be used when targeting
    // with a FreeFormCustomCriteria.
    CustomTargetingValue carModelHondaValue = new CustomTargetingValue();
    carModelHondaValue.setCustomTargetingKeyId(carModelKey.getId());
    carModelHondaValue.setDisplayName("~honda");
    carModelHondaValue.setName("honda");
    // A match type of broad will match anything including "honda",
    // i.e. "~honda".
    carModelHondaValue.setMatchType(CustomTargetingValueMatchType.BROAD);

    // Create the custom targeting values on the server.
    CustomTargetingValue[] customTargetingValues =
        customTargetingService.createCustomTargetingValues(new CustomTargetingValue[] {
            genderMaleValue, genderFemaleValue, genreComedyValue, genreDramaValue,
            carModelHondaValue});

    for (CustomTargetingValue createdCustomTargetingValue : customTargetingValues) {
      System.out.printf("A custom targeting value with ID %d, belonging to key with ID %d, "
          + "name '%s' and display name '%s' was created.%n",
          createdCustomTargetingValue.getId(),
          createdCustomTargetingValue.getCustomTargetingKeyId(),
          createdCustomTargetingValue.getName(), createdCustomTargetingValue.getDisplayName());
    }
  }
1253795
public static void runExample(AdWordsServicesInterface adWordsServices, AdWordsSession session)
      throws RemoteException {
    // Get the CustomerNegativeCriterionService.
    CustomerNegativeCriterionServiceInterface customerNegativeCriterionService =
        adWordsServices.get(session, CustomerNegativeCriterionServiceInterface.class);

    List<Criterion> criteria = new ArrayList<>();

    // Exclude tragedy & conflict content.
    ContentLabel tragedyContentLabel = new ContentLabel();
    tragedyContentLabel.setContentLabelType(ContentLabelType.TRAGEDY);
    criteria.add(tragedyContentLabel);

    // Exclude a specific placement.
    Placement placement = new Placement();
    placement.setUrl("http://www.example.com");
    criteria.add(placement);

    // Additional criteria types are available for this service. See the types listed
    // under Criterion here:
    // https://developers.google.com/adwords/api/docs/reference/latest/CustomerNegativeCriterionService.Criterion

    // Create operations to add each of the criteria above.
    List<CustomerNegativeCriterionOperation> operations = new ArrayList<>();
    for (Criterion criterion : criteria) {
      CustomerNegativeCriterion negativeCriterion = new CustomerNegativeCriterion();
      negativeCriterion.setCriterion(criterion);
      CustomerNegativeCriterionOperation operation = new CustomerNegativeCriterionOperation();
      operation.setOperator(Operator.ADD);
      operation.setOperand(negativeCriterion);
      operations.add(operation);
    }

    // Send the request to add the criteria.
    CustomerNegativeCriterionReturnValue result =
        customerNegativeCriterionService.mutate(
            operations.toArray(new CustomerNegativeCriterionOperation[operations.size()]));

    // Display the results.
    for (CustomerNegativeCriterion negativeCriterion : result.getValue()) {
      System.out.printf(
          "Customer negative criterion with criterion ID %d and type '%s' was added.%n",
          negativeCriterion.getCriterion().getId(),
          negativeCriterion.getCriterion().getCriterionType());
    }
  }
625278
private static void createAdsWithCustomizations(AdWordsServicesInterface adWordsServices,
      AdWordsSession session, List<Long> adGroupIds, String feedName) throws RemoteException {
    // Get the AdGroupAdService.
    AdGroupAdServiceInterface adGroupAdService =
        adWordsServices.get(session, AdGroupAdServiceInterface.class);

    ExpandedTextAd textAd = new ExpandedTextAd();
    textAd.setHeadlinePart1(String.format("Luxury Cruise to {=%s.Name}", feedName));
    textAd.setHeadlinePart2(String.format("Only {=%s.Price}", feedName));
    textAd.setDescription(String.format("Offer ends in {=countdown(%s.Date)}!", feedName));
    textAd.setFinalUrls(new String[] {"http://www.example.com"});

    // We add the same ad to both ad groups. When they serve, they will show different values, since
    // they match different feed items.
    List<AdGroupAdOperation> adGroupAdOperations = new ArrayList<>();
    for (Long adGroupId : adGroupIds) {
      AdGroupAd adGroupAd = new AdGroupAd();
      adGroupAd.setAdGroupId(adGroupId);
      adGroupAd.setAd(textAd);

      AdGroupAdOperation adGroupAdOperation = new AdGroupAdOperation();
      adGroupAdOperation.setOperand(adGroupAd);
      adGroupAdOperation.setOperator(Operator.ADD);

      adGroupAdOperations.add(adGroupAdOperation);
    }

    AdGroupAdReturnValue adGroupAdReturnValue = adGroupAdService.mutate(
        adGroupAdOperations.toArray(new AdGroupAdOperation[adGroupAdOperations.size()]));

    for (AdGroupAd addedAd : adGroupAdReturnValue.getValue()) {
      System.out.printf("Created an ad with ID %d, type '%s' and status '%s'.%n",
          addedAd.getAd().getId(), addedAd.getAd().getAdType(), addedAd.getStatus());
    }
  }
204595
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session)
      throws RemoteException {
    // Get the UserService.
    UserServiceInterface userService = adManagerServices.get(session, UserServiceInterface.class);

    // Get the current user.
    User user = userService.getCurrentUser();

    System.out.printf(
        "User with ID %d, name '%s', email '%s', and role '%s' is the current user.%n",
        user.getId(), user.getName(), user.getEmail(), user.getRoleName());
  }
418097
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session)
      throws RemoteException {
    // Get the ContentService.
    ContentServiceInterface contentService =
        adManagerServices.get(session, ContentServiceInterface.class);

    // Create a statement to get all content.
    StatementBuilder statementBuilder =
        new StatementBuilder().orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);

    // Default for total result set size.
    int totalResultSetSize = 0;

    do {
      // Get content by statement.
      ContentPage page = contentService.getContentByStatement(statementBuilder.toStatement());

      if (page.getResults() != null) {
        totalResultSetSize = page.getTotalResultSetSize();
        int i = page.getStartIndex();
        for (Content content : page.getResults()) {
          System.out.printf(
              "%d) Content with ID %d and name '%s' was found.%n",
              i++, content.getId(), content.getName());
        }
      }

      statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);

    System.out.printf("Number of results found: %d%n", totalResultSetSize);
  }
1123764
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session)
      throws RemoteException {
    // Get the ProductPackageService.
    ProductPackageServiceInterface productPackageService =
        adManagerServices.get(session, ProductPackageServiceInterface.class);

    // Create a statement to select all product packages.
    StatementBuilder statementBuilder = new StatementBuilder()
        .orderBy("id ASC")
        .limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);

    // Default for total result set size.
    int totalResultSetSize = 0;

    do {
      // Get product packages by statement.
      ProductPackagePage page =
          productPackageService.getProductPackagesByStatement(
              statementBuilder.toStatement());

      if (page.getResults() != null) {
        totalResultSetSize = page.getTotalResultSetSize();
        int i = page.getStartIndex();
        for (ProductPackage productPackage : page.getResults()) {
          System.out.printf(
              "%d) Product package with ID %d and name '%s' was found.%n",
              i++, productPackage.getId(), productPackage.getName());
        }
      }

      statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);

    System.out.printf("Number of results found: %d%n", totalResultSetSize);
  }
580184
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session)
      throws RemoteException {
    // Get the InventoryService.
    InventoryServiceInterface inventoryService =
        adManagerServices.get(session, InventoryServiceInterface.class);

    // Create a statement to select all ad unit sizes.
    StatementBuilder statementBuilder = new StatementBuilder();

    // Get all ad unit sizes.
    AdUnitSize[] adUnitSizes =
        inventoryService.getAdUnitSizesByStatement(statementBuilder.toStatement());

    if (adUnitSizes != null) {
      for (int i = 0; i < adUnitSizes.length; i++) {
        AdUnitSize adUnitSize = adUnitSizes[i];
        System.out.printf(
            "%d) Ad unit size of dimensions '%s' was found.%n",
            i, adUnitSize.getFullDisplayString());
      }
    } else {
      System.out.println("No ad unit sizes found.");
    }
  }
1038961
public static void runExample(
      AdWordsServicesInterface adWordsServices, AdWordsSession session) throws RemoteException {
    // Get the CampaignService.
    CampaignCriterionServiceInterface campaignCriterionService =
        adWordsServices.get(session, CampaignCriterionServiceInterface.class);

    int offset = 0;

    // Create selector.
    SelectorBuilder builder = new SelectorBuilder();
    Selector selector = builder
        .fields(
            CampaignCriterionField.CampaignId,
            CampaignCriterionField.Id,
            CampaignCriterionField.CriteriaType,
            CampaignCriterionField.PlatformName,
            CampaignCriterionField.LanguageName,
            CampaignCriterionField.LocationName,
            CampaignCriterionField.KeywordText)
        .in(CampaignCriterionField.CriteriaType, "KEYWORD", "LANGUAGE", "LOCATION", "PLATFORM")
        .offset(0)
        .limit(PAGE_SIZE)
        .build();

    CampaignCriterionPage page = null;
    do {
      page = campaignCriterionService.get(selector);

      if (page.getEntries() != null) {
        // Display campaigns.
        for (CampaignCriterion campaignCriterion : page.getEntries()) {
          System.out.printf("Campaign criterion with campaign ID %d, criterion ID %d, "
              + "and type '%s' was found.%n", campaignCriterion.getCampaignId(), campaignCriterion
              .getCriterion().getId(), campaignCriterion.getCriterion().getCriterionType());
        }
      } else {
        System.out.println("No campaign criteria were found.");
      }
      offset += PAGE_SIZE;
      selector = builder.increaseOffsetBy(PAGE_SIZE).build();
    } while (offset < page.getTotalNumEntries());
  }
543496
private static AdGroup createAdGroup(
      AdWordsServicesInterface services, AdWordsSession session, Campaign campaign)
      throws RemoteException {
    AdGroupServiceInterface adGroupService = services.get(session, AdGroupServiceInterface.class);

    AdGroup group = new AdGroup();
    group.setName("Dynamic remarketing ad group");
    group.setCampaignId(campaign.getId());
    group.setStatus(AdGroupStatus.ENABLED);

    AdGroupOperation op = new AdGroupOperation();
    op.setOperand(group);
    op.setOperator(Operator.ADD);
    AdGroupReturnValue result = adGroupService.mutate(new AdGroupOperation[] {op});
    return result.getValue(0);
  }
288735
public static void runExample(AdWordsServicesInterface adWordsServices, AdWordsSession session)
      throws RemoteException {
    // Get the CampaignService.
    CampaignServiceInterface campaignService =
        adWordsServices.get(session, CampaignServiceInterface.class);

    // Get the CustomerSyncService.
    CustomerSyncServiceInterface customerSyncService =
        adWordsServices.get(session, CustomerSyncServiceInterface.class);

    // Get a list of all campaign IDs.
    List<Long> campaignIds = new ArrayList<>();
    Selector selector = new SelectorBuilder()
        .fields(CampaignField.Id)
        .build();
    CampaignPage campaigns = campaignService.get(selector);
    if (campaigns.getEntries() != null) {
      Arrays.stream(campaigns.getEntries()).forEach(campaign -> campaignIds.add(campaign.getId()));
    }

    // Create date time range for the past 24 hours.
    DateTimeRange dateTimeRange = new DateTimeRange();
    dateTimeRange.setMin(new SimpleDateFormat("yyyyMMdd HHmmss").format(new Date(System
        .currentTimeMillis() - 1000L * 60 * 60 * 24)));
    dateTimeRange.setMax(new SimpleDateFormat("yyyyMMdd HHmmss").format(new Date()));

    // Create selector.
    CustomerSyncSelector customerSyncSelector = new CustomerSyncSelector();
    customerSyncSelector.setDateTimeRange(dateTimeRange);
    customerSyncSelector
        .setCampaignIds(ArrayUtils.toPrimitive(campaignIds.toArray(new Long[] {})));

    // Get all account changes for campaign.
    CustomerChangeData accountChanges = customerSyncService.get(customerSyncSelector);

    // Display changes.
    if (accountChanges != null && accountChanges.getChangedCampaigns() != null) {
      System.out.printf("Most recent change: %s%n", accountChanges.getLastChangeTimestamp());
      for (CampaignChangeData campaignChanges : accountChanges.getChangedCampaigns()) {
        System.out.printf("Campaign with ID %d was changed:%n", campaignChanges.getCampaignId());
        System.out.printf("\tCampaign changed status: '%s'%n", 
            campaignChanges.getCampaignChangeStatus());
        if (!ChangeStatus.NEW.equals(campaignChanges.getCampaignChangeStatus())) {
          System.out.printf("\tAdded campaign criteria: %s%n",
              getFormattedList(campaignChanges.getAddedCampaignCriteria()));
          System.out.printf("\tRemoved campaign criteria: %s%n",
              getFormattedList(campaignChanges.getRemovedCampaignCriteria()));

          if (campaignChanges.getChangedAdGroups() != null) {
            for (AdGroupChangeData adGroupChanges : campaignChanges.getChangedAdGroups()) {
              System.out.printf("\tAd group with ID %d was changed:%n",
                  adGroupChanges.getAdGroupId());
              System.out.printf("\t\tAd group changed status: %s%n",
                  adGroupChanges.getAdGroupChangeStatus());
              if (!ChangeStatus.NEW.equals(adGroupChanges.getAdGroupChangeStatus())) {
                System.out.printf("\t\tAds changed: %s%n",
                    getFormattedList(adGroupChanges.getChangedAds()));
                System.out.printf("\t\tCriteria changed: %s%n",
                    getFormattedList(adGroupChanges.getChangedCriteria()));
                System.out.printf("\t\tCriteria removed: %s%n",
                    getFormattedList(adGroupChanges.getRemovedCriteria()));
              }
            }
          }
        }
        System.out.println("");
      }
    } else {
      System.out.println("No account changes were found.");
    }
  }
32034
public static void runExample(AdWordsServicesInterface adWordsServices, AdWordsSession session)
      throws RemoteException {
    // Get all of the feeds for the session's account.
    List<Feed> feeds = getFeeds(adWordsServices, session);

    for (Feed feed : feeds) {
      // Retrieve all the sitelinks from the current feed.
      Map<Long, SiteLinkFromFeed> feedItems = getSiteLinksFromFeed(adWordsServices, session, feed);

      // Get all the instances where a sitelink from this feed has been added to a campaign.
      List<CampaignFeed> campaignFeeds =
          getCampaignFeeds(adWordsServices, session, feed, PLACEHOLDER_SITELINKS);

      Set<Long> allFeedItemsToDelete = Sets.newHashSet();
      for (CampaignFeed campaignFeed : campaignFeeds) {
        // Retrieve the sitelinks that have been associated with this campaign.
        Set<Long> feedItemIds = getFeedItemIdsForCampaign(campaignFeed);

        ExtensionSettingPlatform platformRestrictions =
            getPlatformRestictionsForCampaign(campaignFeed);

        if (feedItemIds.isEmpty()) {
          System.out.printf("Migration skipped for campaign feed with campaign ID %d "
              + "and feed ID %d because no mapped feed item IDs were found in the "
              + "campaign feed's matching function.%n", campaignFeed.getCampaignId(),
              campaignFeed.getFeedId());
        } else {
          // Delete the campaign feed that associates the sitelinks from the feed to the campaign.
          deleteCampaignFeed(adWordsServices, session, campaignFeed);

          // Create extension settings instead of sitelinks.
          createExtensionSetting(adWordsServices,
              session,
              feedItems,
              campaignFeed,
              feedItemIds,
              platformRestrictions);

          // Mark the sitelinks from the feed for deletion.
          allFeedItemsToDelete.addAll(feedItemIds);
        }
      }

      // Delete all the sitelinks from the feed.
      deleteOldFeedItems(adWordsServices, session, allFeedItemsToDelete, feed);
    }
  }
930336
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session)
      throws RemoteException {
    // Get the ContentMetadataKeyHierarchy service.
    ContentMetadataKeyHierarchyServiceInterface contentMetadataKeyHierarchyService =
        adManagerServices.get(session, ContentMetadataKeyHierarchyServiceInterface.class);

    // Create a statement to get all content metadata key hierarchies
    StatementBuilder statementBuilder = new StatementBuilder()
        .orderBy("id ASC")
        .limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);

    int totalResultSetSize = 0;
    
    do {
      // Get content metadata key hierarchies by statement.
      ContentMetadataKeyHierarchyPage page = contentMetadataKeyHierarchyService
          .getContentMetadataKeyHierarchiesByStatement(statementBuilder.toStatement());

      if (page.getResults() != null) {
        totalResultSetSize = page.getTotalResultSetSize();
        int i = page.getStartIndex();
        for (ContentMetadataKeyHierarchy contentMetadataKeyHierarchy : page.getResults()) {
          System.out.printf("%d) Content metadata key hierarchy with ID %d, and name '%s' was"
              + " found.%n", i++, contentMetadataKeyHierarchy.getId(),
              contentMetadataKeyHierarchy.getName());
        }
      }

      statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);

    System.out.printf("Number of results found: %d%n", totalResultSetSize);
  }
68846
public static void runExample(
      AdWordsServicesInterface adWordsServices, AdWordsSession session) throws RemoteException {
    // Get the MediaService.
    MediaServiceInterface mediaService =
        adWordsServices.get(session, MediaServiceInterface.class);

    int offset = 0;

    // Create selector.
    SelectorBuilder builder = new SelectorBuilder();
    Selector selector = builder
        .fields(MediaField.MediaId, MediaField.Width, MediaField.Height, MediaField.MimeType)
        .orderAscBy(MediaField.MediaId)
        .offset(offset)
        .limit(PAGE_SIZE)
        .in(MediaField.Type, "IMAGE", "VIDEO")
        .build();

    MediaPage page = null;

    do {
      // Get all images.
      page = mediaService.get(selector);

      // Display images.
      if (page != null && page.getEntries() != null) {
        for (Media media : page.getEntries()) {
          Map<MediaSize, Dimensions> dimensions = Maps.toMap(media.getDimensions());
          System.out.printf("Media with ID %d, dimensions %s, and MIME type '%s' was found.%n",
              media.getMediaId(), toString(dimensions.get(MediaSize.FULL)), media.getMediaType());
        }
      } else {
        System.out.println("No images/videos were found.");
      }
      offset += PAGE_SIZE;
      selector = builder.increaseOffsetBy(PAGE_SIZE).build();
    } while (offset < page.getTotalNumEntries());
  }
1138623
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session)
      throws RemoteException {
    // Get the NetworkService.
    NetworkServiceInterface networkService =
        adManagerServices.get(session, NetworkServiceInterface.class);

    // Get all networks that you have access to with the current authentication
    // credentials.
    Network[] networks = networkService.getAllNetworks();

    if (networks == null || networks.length == 0) {
      System.out.printf("No accessible networks found.%n");
      return;
    }

    int i = 0;
    for (Network network : networks) {
      System.out.printf(
          "%d) Network with network code '%s' and display name '%s' was found.%n",
          i++, network.getNetworkCode(), network.getDisplayName());
    }

    System.out.printf("Number of networks found: %d%n", networks.length);
  }
1343610
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session)
      throws RemoteException {
    PackageServiceInterface packageService =
        adManagerServices.get(session, PackageServiceInterface.class);

    // Create a statement to select packages.
    StatementBuilder statementBuilder = new StatementBuilder()
        .where("status = :status")
        .orderBy("id ASC")
        .limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
        .withBindVariableValue("status", PackageStatus.IN_PROGRESS.toString());

    // Retrieve a small amount of packages at a time, paging through
    // until all packages have been retrieved.
    int totalResultSetSize = 0;
    do {
      PackagePage page =
          packageService.getPackagesByStatement(statementBuilder.toStatement());

      if (page.getResults() != null) {
        // Print out some information for each package.
        totalResultSetSize = page.getTotalResultSetSize();
        int i = page.getStartIndex();
        for (Package pkg : page.getResults()) {
          System.out.printf(
              "%d) Package with ID %d, name '%s', and proposal ID %d was found.%n",
              i++,
              pkg.getId(),
              pkg.getName(),
              pkg.getProposalId()
          );
        }
      }

      statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);

    System.out.printf("Number of results found: %d%n", totalResultSetSize);
  }