public static void runExample(
      AdWordsServices adWordsServices, AdWordsSession session, Long adGroupId) throws Exception {
    // Get the AdGroupCriterionService.
    AdGroupCriterionServiceInterface adGroupCriterionService =
        adWordsServices.get(session, AdGroupCriterionServiceInterface.class);

    int offset = 0;
    boolean morePages = true;

    // Create selector.
    SelectorBuilder builder = new SelectorBuilder();
    Selector selector =
        builder
            .fields("Id", "AdGroupId", "MatchType", "KeywordText")
            .orderAscBy("AdGroupId")
            .offset(offset)
            .limit(PAGE_SIZE)
            .in("AdGroupId", adGroupId.toString())
            .equals("CriteriaType", "KEYWORD")
            .build();

    while (morePages) {
      // Get all ad group criteria.
      AdGroupCriterionPage page = adGroupCriterionService.get(selector);

      // Display ad group criteria.
      if (page.getEntries() != null && page.getEntries().length > 0) {
        // Display results.
        for (AdGroupCriterion adGroupCriterionResult : page.getEntries()) {
          System.out.println(
              "Keyword ad group criterion with ad group id \""
                  + adGroupCriterionResult.getAdGroupId()
                  + "\", criterion id \""
                  + adGroupCriterionResult.getCriterion().getId()
                  + "\", text \""
                  + ((Keyword) adGroupCriterionResult.getCriterion()).getText()
                  + "\" and match type \""
                  + ((Keyword) adGroupCriterionResult.getCriterion()).getMatchType()
                  + "\" was found.");
        }
      } else {
        System.out.println("No ad group criteria were found.");
      }

      offset += PAGE_SIZE;
      selector = builder.increaseOffsetBy(PAGE_SIZE).build();
      morePages = offset < page.getTotalNumEntries();
    }
  }