code: private static BundleCapability getExportedPackage(BundleContext context, String packageName) {
          List<BundleCapability> packages = new ArrayList<BundleCapability>();
          for (Bundle bundle : context.getBundles()) {
              BundleRevision bundleRevision = bundle.adapt(BundleRevision.class);
              for (BundleCapability packageCapability : bundleRevision.getDeclaredCapabilities(BundleRevision.PACKAGE_NAMESPACE)) {
                  String pName = (String) packageCapability.getAttributes().get(BundleRevision.PACKAGE_NAMESPACE);
                  if (pName.equalsIgnoreCase(packageName)) {
                      packages.add(packageCapability);
                  }
              }
          }
  
          Version max = Version.emptyVersion;
          BundleCapability maxVersion = null;
          for (BundleCapability aPackage : packages) {
              Version version = (Version) aPackage.getAttributes().get("version");
              if (max.compareTo(version) <= 0) {
                  max = version;
                  maxVersion = aPackage;
              }
          }
  
          return maxVersion;
      }
docs: Return the BundleCapability of a bundle exporting the package packageName.
  
  @param context     The BundleContext
  @param packageName The package name
  @return the BundleCapability of a bundle exporting the package packageName