The practical conclusions, in order of how much difference they make:
Buy whole beans and grind before brewing. This is by far the largest single improvement available to anyone buying supermarket coffee, and it costs the price of a hand grinder.
Look for a roast date rather than a best-before date. Roasters who care print the roast date. A best-before date eighteen months out tells you the producer is not thinking about freshness, and that is itself information.
Buy smaller quantities more often. A large bag that lasts two months is stale for the second month.
Store it sealed, cool, dark and dry — and not in the fridge, where it picks up moisture and odours. The freezer works for long-term storage of unopened bags, and repeatedly taking a bag in and out is worse than a cupboard.